Cannot Load Microsoft.AspNetCore.Razor.Runtime after installing Microsoft.AspnetCore.Authentication.AzureADB2C.UI

I have a simple AspNet Core 3.1.1 web application that compiles and runs fine. It's fair to say that aside from custom HTML and CSS this site is an out of the box project created using a Visual Studio template.

The only added nuget package is BuildWebCompiler 1.12.394 — not quite the latest, though I have tried updating to latest and it doesn't affect the issue that follows.

If I install the nuget package Microsoft.AspNetCore.Authentication.AzureADB2C.UI 3.1.1 everything continues to compile fine. However, I encounter the following exception during Startup.ConfigureServices:

  Message=Could not load file or assembly 'Microsoft.AspNetCore.Razor.Runtime, 
  PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
  Source=<Cannot evaluate the exception source>
  StackTrace:<Cannot evaluate the exception stack trace>

No code or settings have changed within the project except for the nuget installation. The code that throws the exception is:

public void ConfigureServices(IServiceCollection services)
   services.AddRazorPages(); // <--- throws

I have poked around and seen this file not found exception is being raised for several assemblies in connection with Core 3.1.x, but have not found much mention of Razor.Runtime specifically.

There is a nuget for Microsoft.AspNetCore.Razor.Runtime, but its version is 2.2.0. In any case installing this did not seem to help.

2 answers

  • answered 2020-02-12 23:06 Trevor Reid

    Using Microsoft.AspNetCore.Authentication.AzureADB2C.UI 3.1.0 seemed to do the trick.

    I've yet to look into why.

  • answered 2020-02-13 07:57 Nan Yu

    That is a known issue. You can trace related threads here and here. That is because you updated the NuGet package but haven't installed the 3.1.1 runtime yet.

    So you can try below two ways :

    • Downgrading Microsoft.AspNetCore.Authentication.AzureADB2C.UI to 3.1.0
    • Using Microsoft.AspNetCore.Authentication.AzureADB2C.UI version 3.1.1 but upgrading to SDK 3.1.101