简体   繁体   中英

C# Dotnet Core 3.1 - Load Assembly on Runtime

I'm currently trying to load an assembly on Runtime.

I'm using AssemblyLoadContext.Default.LoadFromAssemblyPath(path) . Then, with the DependencyContext and the CompositeCompilationAssemblyResolver , I load unresolved dependcies using - Compile ||Runtime - properties. Finally I fallback to load them directly from the Directory Path if they are yet not found.

However, dependices are still missing on some projects. Like the following

"Cannot find reference assembly 'Microsoft.AspNetCore.Mvc.Core.dll' file for package Microsoft.AspNetCore.Mvc.Core"

Even if it's found inside Compile or Runtime libs, TryResolveAssemblyPaths seems unable to locate them :/

Thanks for your help.

EDIT:

Well, After some research it appears than post 3.1 version of dotnet core framwork, some dependencies are directly loaded inside the SDK itself. Preventing you to load them manually through ICompilationAssemblyResolver or else.

So if you face that probleme with certain projects, apply same SDK on caller/callee (or import them). Microsoft.NET.Sdk.Web for example.

Doc: https://docs.microsoft.com/fr-fr/dotnet/core/project-sdk/overview

And: https://github.com/dotnet/cli/blob/master/Documentation/specs/runtime-configuration-file.md

EDIT 2:

I suggest you to read this issue on github: https://github.com/dotnet/runtime/issues/1050

Mr Vitek Karas answer to this problem in a more accurate manner.

what i am understand is you cannot load your assemply from path

so first get the path

 string path = HttpContext.Current.Server.MapPath("~/bin/dllname.dll");

then

 load =AssemblyLoadContext.Default.LoadFromAssemblyPath(path);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM