0

When I make any change to a CSHTML file while debugging then reload the page, I get this exception. This used to work, and I'm not aware of any changes that could affect this. Googling this error message hasn't been helpful either. Any direction is very much appreciated.

I have tried all the suggestions in https://stackoverflow.com/a/27672935/3397630 without any luck.

I am currently using Visual Studio Community 2022 and .NET 5, but this same thing was happening with 2019.

An unhandled exception occurred while processing the request.

MissingMethodException: Method not found: 'Void Microsoft.CodeAnalysis.CompilationOptions.set_ReferencesSupersedeLowerVersions_internal_protected_set(Boolean)'.

Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.WithReferencesSupersedeLowerVersions(bool value)

TypeInitializationException: The type initializer for 'Microsoft.CodeAnalysis.CSharp.CSharpCompilation' threw an exception.

Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()

Screenshot of error message

tereško
  • 58,060
  • 25
  • 98
  • 150
Ryan
  • 35
  • 6

1 Answers1

0

It sounds like you may need to enable runtime compilation of Razor files: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio

See also: .NET Core 3.0: Razor views don't automatically recompile on change

PeterG
  • 143
  • 4
  • Looks like this is meant for .net 6. Do you know if this is just a bug on .net 5 and we will need to upgrade to fix it? – Ryan Apr 25 '22 at 18:09
  • Just to add more info, I did find this [https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio](https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio) for .net 5, but what they are suggesting is already implemented. – Ryan Apr 25 '22 at 18:15
  • Updated the link to .NET 5 version. Is runtime compilation conditionally enabled? If so are the conditions met to enable it while debugging? – PeterG Apr 25 '22 at 22:15