1
votes

Original post

I am building an ASP.NET application with Visual Studio 2013 Premium for the .NET framework version 4.5, using IIS Express in the debugging process. Now I have run into a problem that happened with other projects before (very very rarely), but is extremely frequently occurring in this one:

Changes in my code often are not compiled correctly and thus an older version of the program is started in IIS. I first noticed this when I got a NullReferenceException in one line of code, then added a check for null around it and then got the same error again, just now in the line where the check happened (which is the line number where the exception occurred before). Another symptom is that no breakpoints are hit anymore because of missing symbols (due to the discrepancy in the version of the code I think).

Now I have read all kinds of threads here and on MSDN regarding this issue, and it seems like many people have this from time to time and noone has a solution that works for everyone.

Doing a clean/rebuild does not work at all when I encounter this problem, but usually deleting the bin and obj folders did the trick. But what happens now is the following:

After starting the debugging process (F5), I can see that my breakpoints aren't hit, so I stop it, delete the bin/obj folders and Rebuild All. This does not work and always fails with many errors saying that a namespace could not be found (even though IntelliSense proposes it there and it does in fact exist) and the assembly (which would provide the namespace) was missing (and it indeed is in the final output folder of the startup project; but it got created in its own project bin folder...). Then I Rebuild All a second time and it will magically work. The next start of the program does everything as I wish it to be. But after that, I am at the point where already the 2nd or 3rd restart produces the problem again (no breakpoints, old code) and I can start over with deleting the folders. I have to add that this behaviour started last week and got ever more frequent since. It wasn't always at the point where I had to delete the folders after every 2nd try.

All this is of course unbearable as it's impossible to work under these circumstances. But I am at a loss as to what to do. I have worked (among others) through this MSDN thread and this SO question, but nothing seems to work for me.

Do you have any other suggestions? Could there be something wrong at some point that produces this kind of behavior explicitly? Especially the part where the first rebuild doesn't but the 2nd does indeed work puzzles me and feels like there could be something I'm doing wrong.

Edit: I tested another scenario right now: After the first rebuild I get the above errors about the missing assembly. Then I really remove the reference to that assembly and despite that, the 2nd rebuild still goes through without errors now! How can that be?

Edit2: So as a summary, every 2nd time I try to run the program with a breakpoint I wish to hit, symbols won't be loaded and I have to delete the bin/obj folders. Then I have to rebuild twice, after the 2nd time it works, starts and hits breakpoints. But the next time after this, it won't hit breakpoints anymore (even if I don't change anything in the code itself!) and I have to start over.

Update

I now tried starting VS as admin and double-checked that the references were project references. After just batch cleaning the whole solution, it would start up but then show me the missing assembly exception for the DataAccess project in IE. I then deleted the bin/obj folders and rebuilt the project once. Now I'm getting (as usual) the following errors:

The type or namespace 'Business' does not exist in the namespace 'MyNamespace' (are you missing an assembly reference?)

Could not resolve this reference. Could not locate the assembly "Business, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

The thing is, the assembly Business.dll lies in the MySolution\Business\bin\Debug folder as well as in the final MySolution\Frontend\bin folder, and it is definitely the version that I just built. So why does the compiler complain? It feels like there's something wrong with the build order, but that shouldn't be the case if I purely use project references, should it?

Now, again as usual, the 2nd rebuild works fine, and I can hit my breakpoints once after that. Then I added a trivial line int i = 0; in the code right after the breakpoint and restarted the program, and again it tells me the breakpoint won't be hit and that symbols aren't loaded. I then checked Debug -> Windows -> Modules to see

Cannot find or open the PDB file.

for the Business and DataAccess projects while yesterday I got

PDB does not match image.

for those.

But when right clicking the Business project in Modules and selecting Load symbols, it immediately prompts me to the obj\Debug folder of theproject where a*.pdb` file resides that has been created on build (confirmed via the timestamp). Choosing this file yields

A matching symbol file was not found in this folder.

But I just clicked that file, so there must be something wrong with the 'matching' part, right? Do you have any further ideas, as I'm totally out of knowledge here?

Update 2

After updating Visual Studio 2013 to Update 3 I get an additional compiler warning when doing the first Rebuild All after deleting the bin/obj folders:

The type 'MyNamespace.Business.Providers.BusinessProvider' exists in both 'MySolutionPath\StartupProject\bin\Business.dll' and 'MySolutionPath\Business\bin\Debug\Business.dll'.

I wonder if/why this is an issue, as it is VS itself that must have copied the Business.dll to the StartupProject's bin folder. Could that maybe point to anything worth looking at?

3
Are you running visual studio as an administrator on the system? Sounds like a permissions issue.C Bauer
@CBauer I will try this (currently restarting the VM which can take a lot of time), but I think I already am. At least I had no problems whatsoever in the 80 days it took for this application to come to this point.InvisiblePanda
Check your references: do the references to your own projects point to that project, or to a compiled dll in a bin folder? They should point to the projects.Hans Kesting
@HansKesting They are all project references, added via the VS Add Reference dialog in this way. I think I found some more information, gonna check back tomorrow!InvisiblePanda
Your solution configuration manager, is it out of whack in terms of which projects are building to what output? If your main project has a reference to the sub project (business) -- it should grab the output. If you're getting duplicates, you can tell the main project to not copy the files (select the reference, find copy-to-output in properties and choose false).Jason

3 Answers

0
votes

After trying out everything I found regarding this or similar issues, the only thing that helped me in the end was to delete the whole solution locally and do a clean check-out from TFS again. After that it worked as expected again, and I still don't know what caused it, as I had even checked in before and thus the version I deleted should have been identical to the one I checked out.

0
votes

I just had similar issues (with a Windows Forms project) and it turned out the code I changed was in an event handler, which had been thrown out of the designer file for whatever reason. If the added code was correct, the project would compile, but it was of course never hit. What still puzzles me is how my gridview got sorted without this event, but I remember that when I wrote it, I was thinking "This should just work without throwing code at it", so maybe somewhere along the line, I unknowingly corrected the issue some other way. Anyway, I hope this helps anyone.

0
votes
  1. close the solution. 2.Delete bin and obj folders from project folder. 3.open the solution in visual studio Menu>build>Cleansolution, build the application. run the app and verify the changes .if you still see the same issue> do another small change in UI and rebuild the application. It works fine.