Home > Enterprise >  Visual Studio - ASP.NET Core - Problems when I add a new class
Visual Studio - ASP.NET Core - Problems when I add a new class

Time:01-27

I wanted to integrate a Microsoft Sign-In functionality into my ASP.NET core site. When reading following section in the Microsoft Docs, they suggest to download a preconfigured project which has a bit of configuration done for you. Link: enter image description here

When going over the red lines it points me to CS0116:A namespace cannot directly contain members such as fields or methods.

Does someone know whats going on here or am I just blind?

CodePudding user response:

Namespaces cannot contain dash characters -

The reason the error says

CS0116:A namespace cannot directly contain members such as fields or methods.

Is because of the dashes -, it thinks you are trying to perform a mathematical operation and subtract a variable or object named OpenIDConnect from namespace WebApp, which is not allowed.

You could instead:

  1. Use a period . if these are meant to be nested namespaces
  2. Use underscores _
  3. TitleCase your namespaces by just removing the dashes
  •  Tags:  
  • Related