12

I'm not sure if anyone else has encountered this but often, when I open this particular solution, I see a whole list of errors (see below).

Error Image

If I double click one of them, then Visual Studio seems to wake up and the errors relating to that particular cs file disappear. This isn't a critical issue and is more on an irritation than anything else but I wonder, is there perhaps something wrong with my code that's causing this false-positive or is it random Visual Studio behaviour?

Daniel
  • 2,167
  • 5
  • 23
  • 44

3 Answers3

22

I had this problem too. Deleting bin and obj folders not work. Cleaning solution not work. Various platform I need to be as is.

Helped me close solution and delete folder .vs, which is often full of problematic mess. After opening solution all false errors disappeared.

bmi
  • 652
  • 2
  • 10
  • 17
  • 4
    In fact I just tried ***only*** deleting the `.vs`. folder, without even deleting bin/obj, cleaning solution, rebuilding, or anything else, and when I reopened Visual Studio, it worked, the errors were gone! – jbyrd Sep 20 '19 at 19:35
  • 2
    Thank you for this. I had to delete the .vscode/ directory to resolve the issue. – MrToast Feb 03 '21 at 09:19
  • 1
    Thank you. This really helped me out. Apparently that stuff caches too(?). I went from 1:40 timer on my game to 5:22... by doing this it went back to normal. – I try so hard but I cry harder Dec 22 '21 at 16:04
10

As mentioned in a comment, you can do a Clean and Rebuild. If that does not work for you, you can browse to the solution folder and within each of the project folders delete the bin and obj folders. Then perform a build.

You may also want to look into your Configuration Manager and ensure that all of your projects are set to the same Configuration (Debug/Release) and Platform (Any CPU/x86/etc...) and marked to build for that configuration.

Finally, you may also want to check the Build Order for your solution. Ensure that projects are all built in the proper order.

-- Edit:

On thing brought up in comments that I will add here was to make sure that any library projects in the solution are added as Project References rather than referencing the output DLL directly.

gmiley
  • 6,531
  • 1
  • 13
  • 25
  • I have a single solution with a Web-project and a C# project (DataLayer) in the same solution. The C# project, when compiled, builds the DLL that drops into the bin folder of the web-project. Is this possibly why this is occurring? Another thing I noticed is that the C# project is in a folder within the Web-project so I need to somehow exclude it however there is no option when I right-click it. – Daniel May 18 '17 at 10:42
  • Are you using the project as a reference or are you building the project, then using the output DLL as a reference? If the project is contained within the solution, you should reference the project itself and not the output library. I'm not sure what you mean by your last couple sentences. Your projects should be at the same level with the output from your library being copied into your web project output. But that should all be done automatically if the library project is referenced. – gmiley May 18 '17 at 10:45
  • 1
    To be honest, I learned C# to fix this stalled internal project so I literally just carried on with what was there when I started. There are plenty references to the project via the `using` statements at the beginning of each file. I would assume I'm building the project and using the output DLL as a reference but I could be wrong. Apologies for my ignorance here. – Daniel May 18 '17 at 10:50
  • 1
    No, I mean how is the library referenced, when you added it as a reference did you add it through the `Projects` tab, or did you add it through the `Browse` tab and select the output DLL file? If you are indeed referencing the DLL file directly, I would change that and select the project through the `Projects` tab in the `Add References` window. That ensures that the library project is built every time a change is made. – gmiley May 18 '17 at 10:55
  • 1
    I'm not sure how it was added but I'm currently doing it the way you're suggesting, I can see the logic in your suggestion and am just handling how to move the project out of the main web-project's directory – Daniel May 18 '17 at 10:59
  • 1
    Thank you so much! I removed the project from the solution, moved the folder, added the project, added the reference and all errors disappeared! – Daniel May 18 '17 at 11:04
  • 2
    I'll add that suggestion to the answer as well then. – gmiley May 18 '17 at 11:05
  • Clean and Rebuild did not work for me. However, I didn't need to delete the `bin` and `obj` folders. I simply ran the `Configuration Manager`, edited my settings (but leaving them the same as they were) and saved. The spurious errors then disappeared. Thank you for the guidance. – Christopher Hull Jun 26 '23 at 14:50
1

Something that has only become evident in later years, and is only relevant upon reflection on this old question, is that the particular solution that we experience this issue in contains a Website project and NOT a WebApplication project. This became evident when we started to look deeper into these recurring errors and noted that they only ever related to codebehind files and all had to do with the Control Name not existing in the current context.

Amongst the various differences between the two project types, it seems that the lack of designer files for each ASP page may be a contributing factor. The error disappears as soon as you double click it potentially indicating that VS is not able to keep track of the control references until you open the relevant page / codebehind file.

We're moving over to a Web Application as a temporary measure.

Hope this insight helps someone else!

Daniel
  • 2,167
  • 5
  • 23
  • 44