diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CSharpCompiler.cs b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CSharpCompiler.cs index 107040ef4e..d95de2584b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CSharpCompiler.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CSharpCompiler.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Hosting; @@ -154,11 +155,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal var parseOptions = new CSharpParseOptions(preprocessorSymbols: defines); - LanguageVersion languageVersion; - if (!string.IsNullOrEmpty(dependencyContextOptions.LanguageVersion) && - Enum.TryParse(dependencyContextOptions.LanguageVersion, ignoreCase: true, result: out languageVersion)) + if (!string.IsNullOrEmpty(dependencyContextOptions.LanguageVersion)) { - parseOptions = parseOptions.WithLanguageVersion(languageVersion); + if (LanguageVersionFacts.TryParse(dependencyContextOptions.LanguageVersion, out var languageVersion)) + { + parseOptions = parseOptions.WithLanguageVersion(languageVersion); + } + else + { + Debug.Fail($"LanguageVersion {languageVersion} specified in the deps file could not be parsed."); + } } return parseOptions; diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/CSharpCompilerTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/CSharpCompilerTest.cs index b25b4127b0..c6d9b94dd2 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/CSharpCompilerTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/CSharpCompilerTest.cs @@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal // Arrange var dependencyContextOptions = new DependencyContextCompilationOptions( new[] { "MyDefine" }, - languageVersion: "CSharp7_1", + languageVersion: "7.1", platform: null, allowUnsafe: true, warningsAsErrors: null,