dotnet/systemweb-adapters

Dependency Issue: Could not load file or assembly Microsoft.Extensions.Options

cswagerty opened this issue · 1 comments

Describe the bug

I'm working on implementing remote Authentication between a .NET Core and .NET Framework app following this article. Locally, the app works as expected, but when deployed to IIS I see the following error on the .NET Framework app.

"Could not load file or assembly 'Microsoft.Extensions.Options"

Screenshot 2023-10-11 at 4 59 01 PM

I believe the issue is due to an existing dependency in our packages.config

<package id="Microsoft.Extensions.Options" version="7.0.0" targetFramework="net48" />

I'm seeing \bin\Microsoft.Extensions.Options.dll, but the Product number on the file is listed as 7.0.0, and SystemWebAdapters calls for 6.0.0.

When I installed Microsoft.AspNetCore.SystemWebAdapters, it added the following to Web.config, so I thought it should be looking for 7.0.0. instead of 6.0.0 in the error message

      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Options" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.1" newVersion="7.0.0.1" />
      </dependentAssembly>

Any idea why I'm seeing this runtime error? Is there a workaround that I'm missing or something else I should check?

Thanks in advance for the tools and support!

To Reproduce

Repo with MRE (but issue is not reproducible locally) https://github.com/cswagerty/dotnet-migration-auth-mre.

Exceptions (if any)

Server Error in '/' Application.
Could not load file or assembly 'Microsoft.Extensions.Options, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Options, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.Extensions.Options, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace:


[FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Options, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.RemoteAppServerExtensions.AddRemoteAppServer(ISystemWebAdapterBuilder builder, Action`1 configure) +0
...

Further technical details

Please include the following if applicable:

ASP.NET Framework Application:

  • Technologies and versions used (i.e. MVC/WebForms/etc): MVC
  • .NET Framework Version: 4.8
  • IIS Version: 10.0
  • Windows Version: Windows Server 2019 Datacenter

Upon investigation, the deployed Web.config file did not contain the bindingRedirect, which was causing this issue. After adding everything is working like a charm. Thanks for all of the work on this excellent library!