4

I have a console application on net 5.0. I'm trying to load assembly at runtime:

Assembly loadedAssembly = Assembly.LoadFrom(assemblyPath);
var controllers = loadedAssembly.GetExportedTypes();

Method GetExportedTypes throws this exception

Could not load file or assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

I don't have such library in any of my project files. Assembly also has target framework 5.0

Can't find similar error by search in internet. What it can be?

Stefano Cavion
  • 641
  • 8
  • 16

1 Answers1

2

Add

<FrameworkReference Include="Microsoft.AspNetCore.App" />

to the erroring projects csproj or vbproj file and the error will disappear.

Edit:

The error can occur with v6 DLLs as well:

Could not load file or assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=6.0.0.0

The solution is to remove the PackageReference and replace it with the FrameworkReference.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321