Hot-patching "deps.json" at runtime?

Karsten Schramm 0 Reputation points
2023-09-20T06:20:51.46+00:00

I have a .NET 6.0 DLL that contains an Entity Framework Core DbContext to a SQL Server database.

If that assembly is referenced by the .NET 6.0 EXE and then called, everything works just fine.

However, if I try to use it in a plug-in concept and load the DLL via reflection like this:

var assembly = Assembly.LoadFrom("Plugin.dll");
var pluginType = assembly.GetExportedTypes()
  .Where(t => t.IsAssignableTo(typeof(IPlugin)))
  .First();
var plugin = (IPlugin)Activator.CreateInstance(pluginType);

Then I get

Microsoft.Data.SqlClient is not supported on this platform.

And the only difference is in the PluginHost.deps.json that now has no clue that at some point Microsoft.Data.SqlClient may get involved.

enter image description here

And I was wondering if there was some hot-load function to teach the EXE the dependencies of the DLL.

The whole test endeavor can be found on GitHub

Developer technologies C#
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-10-05T16:00:09.4633333+00:00

    generally for msbuild, the dependency tree is defined by nuget packages added. each nuget package has a list of other packages they depend on. if a project reference is added, then the project file has the dependencies.

    some packages dynamically access their dependencies at runtime. for example ef core does require any database drivers at build. these are discovered at runtime via the connection string. the app generally adds the nuget package of the desired drivers so they will be included in the publish.

    so if your plugin dll requires other libraries, they should be included with the plugin and copied to the bin folder. you probably want to define a dependencies type file for the plugins. your code will also have to resolve if two plugin have conflicts.

    the optional myapp.deps.json is used by the pack/service installer. if you are making use of this, when you add a plugin, you need to add all its dependencies. that is you need to patch before your app is installed,


  2. Karsten Schramm 0 Reputation points
    2023-10-18T08:25:46.14+00:00

    I found the answer by this blog post and the nuget provided therein.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.