0

I'm trying to load DLLs from my app do some investigation. I use LoadFrom to load them like this

Assembly.LoadFrom("C:/Dev/MyApp/My.Dll");

and it fails with

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   ...

If I list modules while running the app I see

C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\8.0.18\Microsoft.AspNetCore.Mvc.Abstractions.dll

Why it doesn't get loaded in my side-app? How to make it work?

1
  • Are you trying to load an assembly using the absolute path? In principle, it can work, but it would be absolutely useless for any decent software product, because the operation would be based on absolutely nonrealistic assumptions about the user environment. Or is it just the test? And this is not how the library or package assemblies are normally loaded, so no wonder the loading fails. Commented Aug 18 at 22:05

1 Answer 1

0

Microsoft.AspNetCore.Mvc.Abstractions sits in C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\x.x.x\. So we need to add this path to list of probing paths. This can be done with this change

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

We can check difference before and after by using this call

AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES")

Before adding FrameworkReference

C:\Program Files\dotnet\shared\Microsoft.NETCore.App\x.x.x\;

After adding FrameworkReference

C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\x.x.x\;C:\Program Files\dotnet\shared\Microsoft.NETCore.App\x.x.x\;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.