1
 private void Context_EndRequest(object sender, EventArgs e)
    {
        var context = ((HttpApplication)sender).Context;
        if (context.Items[typeof(IServiceScope)] is IServiceScope scope)
        {
            scope.Dispose();
        }
    }

When I try to build my project (Framework 4.7.2) I am getting the

: error CS1026: ) expected : error CS1002: ; expected : error CS1513: } expected

On the line

if (context.Items[typeof(IServiceScope)] is IServiceScope scope)

But I don't see where it's throwing the error.

mason
  • 31,774
  • 10
  • 77
  • 121
Dario M.
  • 415
  • 7
  • 21
  • 7
    Check the C# version in the Build properties of your project. You're using "pattern matching", introduced in C# 7. – CodeCaster Aug 09 '19 at 13:13
  • Was `obj is Scope scope` already implemented in _4.7.2_? – Maxime Recuerda Aug 09 '19 at 13:14
  • 6
    @MaximeRecuerda That's a language feature, not a .Net Framework feature – phuzi Aug 09 '19 at 13:15
  • 4
    Pattern matching is a language feature introduced in C# 7 or later, not a .NET feature. The framework version doesn't matter. – Panagiotis Kanavos Aug 09 '19 at 13:15
  • go to the properties of your project then to [Build] then scroll down to the end and click [Advanced] then choose a C# [Language Version] that is higher than 7.0. – Mong Zhu Aug 09 '19 at 13:22
  • 1
    @phuzi You enlightened my life, I always thought I was stuck with C# 6 because I couldn't upgrade my framework! – Maxime Recuerda Aug 09 '19 at 13:23
  • My Language Version is C# latest major version (default)... I already tried one Version higher then 7.0. I tried C# 7.3 but then I get the error "invalid option '7.3' for /langversion; must be ISO-1,ISO-2, Default or an integer in range 1 to 6" – Dario M. Aug 09 '19 at 13:25
  • Well using C# 7 is the solution. Research that error message. Also, which Visual Studio version do you use? See also https://stackoverflow.com/questions/31868803/error-invalid-option-6-for-langversion-must-be-iso-1-iso-2-3-4-5-or-defa – CodeCaster Aug 09 '19 at 13:33
  • I had to update "Microsoft.Net.Compilers" ! No it's building... thanks for the help – Dario M. Aug 09 '19 at 13:34
  • @user1861065 you don't have to do that with Visual Studio 2019. Which version are you using? – Panagiotis Kanavos Aug 09 '19 at 13:39
  • Visual Studio 2017 :-( – Dario M. Aug 09 '19 at 13:40

1 Answers1

1

It helped to update "Microsoft.Net.Compilers" over Nuget

now it builds without error.

mason
  • 31,774
  • 10
  • 77
  • 121
Dario M.
  • 415
  • 7
  • 21
  • 1
    You should also mention you had to change the C# version, so that your answer is complete. – mason Aug 09 '19 at 14:07