solving program corruption in c#, VS2008

g_johnson
g_johnson used Ask the Experts™
on
I have written a c# com-enabled dll using VS2008.  The dll works fine.

However, in recent attempts to add to the dll, I am getting strange things that I believe are caused by some sort of corruption.

In essence, when I add variables to a method, they will not instanstiate, though the original variables are fine.  For example, in this code snippet,

        [ComVisible(true)]
        public int CreateXML(ref string ErrMess)
        {
            string phase = "";
            string whatever = "";

            try
            {
                whatever = "1";
                MessageBox.Show("Remove this readxml which is for testing changes only");
                this.ReadXML();

if you hover over "phase" or look at it in the immediate window it is instantiated and holds the value of an empty string.

If you hover or "whatever" you get nothing, and the immediate window returns "The name 'whatever' does not exist in the current contextt".

This probelm occurs on at least two different methods within the dll.

I have tried a Clean then Build without any luck.  I have compeletely deleted the bin folders and then done a Build, no luck.  I have tried writing a new method, no luck.  I have done the same for the app that calls the dll, no luck.

Any thoughts?

Thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Are you trying to debug a debug build or a release build? How are you doing the debuggin... what project(s) are open in your IDE... the calling app, and/or the target dll?

Author

Commented:
I am debugging a debug build.  Both the calling app and the dll are open in the IDE -- the only two projects in the solution.  

I'm not sure what you mean by "how are you doing the debugging?" but I set a breakpoint in the code, for example, at "whatever = 1" then check the immediate value of the variables.  If I hover over "phase" in the above, or check it in the immediate window, it's fine (that's an original variabble).  For "whatever", it does not exist.

Thanks.
Commented:
It sounds very much like you're referencing an old version of the dll, thus the source code isn't matching the target dll.

Check the references in the main app, where it references the dll... make sure it's pointing to the correct location of the (debug build) dll output. Perhaps even remove the reference then add again, making sure you add it from the 'projects' tab in references.

When running, if you open up the Modules debug window that also shows you the path names of the dlls that have been loaded... Try checking that to see you're looking at the right binary.

If you add some debug e.g. Console.WriteLine(..) or something in your app, does that get run? Shove a messageBox.Show(..) in the middle of the function to make sure a 'build' really does recompile the source code.

Commented:
Oohh.. Try a 'clean' then check that the .pdb files have also been removed (and delete if not) in case they're corrupted somehow. Then rebuild..

Author

Commented:
Excellent.  Thank you very, very much!  I deleted the reference and then added it back in and the problem was solved.  It was very strange, because some things were working (such as adding in a message box, certain other variables), but most weren't.  Thanks again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial