Using VS2017 RC, .NET Core
I am trying to load an assembly from a file. The dependencies of this assembly are in the same folder.
I am using AssemblyL
There is a great enhancement in .Net Core 3.0+, wire AssemblyLoadContext.Default.Resolving
event as given below and all dependencies will be resolved and loaded:
AssemblyLoadContext.Default.Resolving += (context, name) => {
string assemblyPath = $"{pluginFolder}\\{name.Name}.dll";
if (assemblyPath != null)
return context.LoadFromAssemblyPath(assemblyPath);
return null;
};
Remember to define the variabe pluginFolder
Solution2
You can use the AssemblyDependencyResolver
class and resolve dependendencies including ones in .deps.json
:
var resolver = new AssemblyDependencyResolver(pluginPath);
AssemblyLoadContext.Default.Resolving += (context, name) => {
string assemblyPath = resolver.ResolveAssemblyToPath(name);
if (assemblyPath != null)
return context.LoadFromAssemblyPath(assemblyPath);
return null;
};