12

I just started my first project with c#8 and immediately I'm hit with warnings everywhere on my properties. After some research, it looks like I'm now supposed to explicitly add a ? to any properties that can be null.

Two questions:

  1. If I port code from previous versions to this version, does this actually affect runtime in anyway whatsoever, or do I just have to ignore a bunch of warnings?

  2. Is there a simple switch to revert to the old behavior so it won't show these warnings? I understand that there are ways I could update my code in a million places to ignore the warnings... I don't want to do that. It's a waste of time and I'd rather live with them if they don't actually affect anything at runtime. But if there is something I can do in a single place to get rid of them that would be great.

BVernon
  • 3,205
  • 5
  • 28
  • 64
  • 1
    Does this answer your question? [How to all #nullable disable to all files in solution](https://stackoverflow.com/questions/69119049/how-to-all-nullable-disable-to-all-files-in-solution) – GSerg Nov 08 '22 at 22:47
  • 2
    Does this answer your question? [Disable null validation in ASP.Net 6 project](https://stackoverflow.com/q/71350179/11683) – GSerg Nov 08 '22 at 22:49
  • @GSerg Yes, the 2nd one seems to do the trick. Thank you. – BVernon Nov 09 '22 at 03:37

1 Answers1

14
  1. The nullability analysis feature only reports warnings, it doesn't affect runtime in any way.
  2. Yes you can suppress those diagnostics, <Nullable>disable</Nullable> in the project file or #nullable disable at the top of your source file will do it.
Julien Couvreur
  • 4,473
  • 1
  • 30
  • 40