.Net application – C# – resolving error – S8370 Feature ‘nullable reference types’ is not available in C# 7.3. Please use language version 8.0 or greater.

C# - Error (active) CS8370 Feature 'nullable reference types' is not available in C# 7.3. Please use language version 8.0 or greater.
C# - Error (active) CS8370 Feature 'nullable reference types' is not available in C# 7.3. Please use language version 8.0 or greater.

Hi All,

Greetings for the day!!!

Today new issue and solution. Today’s issue bit different than Microsoft 365. Its related to C#.

I am not C# expert but still sharing since it save time.

Background

  • I am working .NET application where I am accessing Graph APIs.
  • I am using Visual Studio 2022.
  • I am using .Net Framework 4.8. This is the default framework coming for me. Though I was looking for .NET framework 8.0.
C# - Windows Application

fig : C# – Windows Application

  • For storing client app id and other details I am using “Settings” class which is derived from “System.Configuration.ApplicationSettingsBase” class.

[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{

    private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

    public static Settings Default
    {
        get
        {
            return defaultInstance;
        }
    }
}

  • I have added my custom class called “GraphHelper.cs” for authenticating Graph APIs.
  • In this class I have “Setting” class nullable instance as
namespace MS_Graph_Demo
{
    internal class GraphHelper
    {
        // Settings object
        private static Settings? _settings;
        // App-ony auth token credential
        private static ClientSecretCredential? _clientSecretCredential;
    }//cs
}//ns

  • Here, in above code on declaration of “Settings” instance I am getting an error as

Issue

C# - Error (active) CS8370 Feature 'nullable reference types' is not available in C# 7.3. Please use language version 8.0 or greater.
fig : C# – Error (active) CS8370 Feature ‘nullable reference types’ is not available in C# 7.3. Please use language version 8.0 or greater.

Error (active) CS8370 Feature ‘nullable reference types’ is not available in C# 7.3. Please use language version 8.0 or greater.

Cause

  • My project is configured for C# 7.3, we need to change the language version.

Solution

  • Once we have configured our project for C# 8.0, and with Nullable Reference Types enabled, Roslyn, the C# compiler, will understand nullability annotations. It will give code analysis based on them.
  • We can enable “nullable reference types” feature for the whole project.
  • To enable Nullable Reference Types for all code in a project, we need to update the .CSPROJ file
  • Close the solution in Visual Studio.
  • Open the .CSPROJ file in text editor (I am opening in NOTEPAD) and add the below lines in .CSPROJ file as

<Nullable>enable</Nullable>
<LangVersion>8.0</LangVersion>
C# - Updating .CSPROJ file in text editor - Enabling Nullable reference
fig : C# – Updating .CSPROJ file in text editor – Enabling Nullable reference
  • Open the solution in Visual Studio.
  • Build it again and solution get successfully build.

Have a wonderful day ahead!!!

Thanks for reading !!!

REFERENCES

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.