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

Viewed 64

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

I added a custom class to my project following the 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.

P.S. 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.

1 Answers

P.S. 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.

Related