What are the challenges you face when working across database platforms? Take the survey
Options

Possible to resolve embedded assemblies via MetadataLoadContext?

jpeirsonjpeirson Posts: 1 New member
I have a .NET Core 3.1 application that temporarily loads plugin assemblies in a separate context to discover what plugins are available. Plugins are always stored on disk as separate assemblies, but the common API assemblies are embedded into the main app using SmartAssembly (7.5.2).

I found this article on how to do this with .NET Framework. However, our application uses MetadataLoadContext to discover plugins, not AppDomain.

Our code for discovering plugins looks something like:
var resolver = new PathAssemblyResolver(pathsToApiAssembliesOnDisk);
using var mlc = new MetadataLoadContext(resolver);
var pluginAssembly = mlc.LoadFromAssemblyPath(possiblePluginAssemblyPath);
return ReadPluginMetadata(pluginAssembly);
This works perfectly fine without using SA to embed the common API assemblies into the main app. However, after embedding, reading the pluginAssembly will fail with something like:

"System.IO.FileNotFoundException: Could not find assembly 'CommonPluginApi'. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly."

I understand that this error happens because the "CommonPluginApi" assembly is embedded and resolved by SA at runtime. So the question is: how can I tell MetadataLoadContext to find the 'CommonPluginApi' assembly via SA's assembly loader?

Thanks,
-Jeff
Sign In or Register to comment.