© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
44 replies
Immortal

✅ Best practices regarding non-nullable property warnings?

Hi, In my Discord Bot project I get some warnings for example:

Non-nullable property 'Config' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

I understand what it means and why I get it but not sure if it's ok for me to ignore it or if it indicates bad practices so I should learn to write it better.

Here is my Program.cs file:
namespace self_bot
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var bot = new Bot();
            bot.RunAsync().GetAwaiter().GetResult();
        }
    }
}
namespace self_bot
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var bot = new Bot();
            bot.RunAsync().GetAwaiter().GetResult();
        }
    }
}

And I've attached the Bot.cs file contents because it's too long to be put in this message.

The warning also shows with the Client and Slash properties.

From looking online the best way would either be to use lazy initialization or a constructor but I have no clue which is best for my project so would like advice from more experienced people.

Thanks
bot.txt5.05KB
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Non-nullable property netstandard2.0
C#CC# / help
13mo ago
❔ JSON serialization nullable warnings (best approach?)
C#CC# / help
3y ago
✅ Dealing/resolving nullable warnings
C#CC# / help
3y ago
deserialize non-nullable
C#CC# / help
2y ago