简体   繁体   中英

Why does Visual Studio incorrectly show errors in intellisense, but not build?

I have a class named Strings which has some const strings. I am referencing these consts from another class named TestScript1 .

Both Strings and TestScript1 are in the same project.

Intellisense is reporting an error when I access the consts from Strings in TestScript1 as shown in the following image:

在此处输入图片说明

However, if I compile and run the project, everything works fine - no compile errors, no runtime exceptions. Furthermore, if I change the error window to show "Build Only" errors, no errors appear on build, but I still see the squiggly red underlines.

Things I've tried:

  • Including the fully-qualified name instead of a using.
  • Restarting Visual Studio
  • Deleting the .suo file in the .vs folder
  • Clean and Rebuild

Is there anything I can do to get Visual Studio's intellisense to realize that this is not in fact a compile error?

Update 1: Here's some more details and things I've tried.

The Storyvania.DataTypes namespace contains 5 other classes. Those all show up just fine in intellisense, it's just the Strings class.

I am using Visual Studio Community 2017, Version 15.4.1.

The problem I'm experiencing is not only a syntax error but the dropdown that appears when typing does not recognize the Strings class.

I've also tried (to no avail):

  • Changing the const strings to static
  • Changing the Strings class to itself being static
  • Making the Strings class public (it shouldn't matter because they're in the same project, but I tried it anyway)
  • I mentioned it above but in case it wasn't clear, I tried accessing the fully-qualified Storyvania.DataTypes.Strings rather than just Strings with a using statement.
  • Restarting Visual Studio after all of the above.

VS 2019 also has the problem. It seems that VS fails to clear/update some of the data they cache. Try deleting folders named .vs from root of your repository/solution and its subfolders.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM