[SOLVED] How to use newer language features in an ASP.net website?

Issue

I’m trying to use a local function in my asp.net web-site:

public class Handler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        Int32 Seven()
        {
            return 7;
        }
    }
}

But i get an compile-time error:

CS8026 Feature ‘local functions’ is not available in C# 5. Please use language version 7.0 or greater.

Ok then.

How to use Language Version 7.0 or greater in an ASP.net web-site?

It seems everyone knows how to upgrade an ASP.net web-application to a newer version of C#. But how to you upgrade an ASP.net web-site to a newer version of C#?

One person suggests going into the properties of your project; forgetting that web-sites don’t have projects (again, that’s web applications).

Someone else suggests adding magic cargo-cult programming to your web.config:

<system.codedom>
  <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
  </compilers>
</system.codedom>

except that just causes more compile-time errors:

The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.

Someone else suggests you install something (Microsoft.CodeDom.Providers.DotNetCompilerPlatform); except he doesn’t explain what that is, or how to install it.

Stop fumbling around

So that’s enough Googling, randomly trying half-answers that cause more problems. It’s time to get the answer.

What is the correct, complete, actual, designed, supported, intended way to use C# 8 in an ASP.net web-site?

Bonus:

-

Solution

Changing the Target Framework to 4.8 should get you C# 7.3 features. C# features are standardized and correspond with the framework version.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version

Answered By – beautifulcoder

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *