简体   繁体   中英

Is the name Secrets an invalid name for a class in C#

I am probably making a dumb error but I cannot see it.

I added a custom class to my project followingthe simple Newtownsoft example here .

namespace MyApp
{
     public class Secrets
     {
          public string Test {get;set;}
     } 
}

But when I go to reference the class in my Program.cs:

      namespace MyApp
      {
          static class Program
           {
              [STAThread]
              static void Main()
               {
                 <snip>

                 string json = FetchJson();
                 var MySecrets = JsonConvert.DeserializeObject<Secrets>(json);   // this line
               }
           }
      }
 

Visual Studio underlines <Secrets> and says the type or namespace 'Secrets' cannot be found. But the project compiles without error.

If I change the name of the class to Sekrets then Visual Studio finds it and is happy.

PS And if I then rename the file from Sekrets.cs back to Secrets.cs and let VS make the global change, then VS remains happy, no error, no red underlining.

PS And if I then rename the file from Sekrets.cs back to Secrets.cs and let VS make the global change, then VS remains happy, no error, no red underlining.

Sounds like an Intellisense database problem, you generally fix those by closing VS and then deleting your .vs folder. Next time you open your solution, VS will rebuild the database from scratch.

Luckily it almost never happens in C#, since it's a much easier language to parse than C++. Intellisense really has problems parsing that.

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