PluginLoader.CreateFromAssemblyFile fail when dependency is in two packages
See original GitHub issueDescribe the bug
Having two packages where one package contain a library that is also in the other package, PluginLoader.CreateFromAssemblyFile
when iterating deps file, adding managed libraries.
To Reproduce
EDIT 1/11: Reproduction repo provided in later comment.
Steps to reproduce the behavior:
- Create a library Lib1 (e.g
dotnet new classlib
). Package it. - Create another library, Lib2, and package it, but include Lib1.dll in that package too.
- Create an application referencing both packages (e.g
dotnet new console
). (I used a local feed and aNuGet.config
) - Load the application with
PluginLoader.CreateFromAssemblyFile
.
Expected behavior The application load fine and loader resolves what library to use.
Additional context
Failure is when AssemblyLoadContextBuilder.AddManagedLibrary
tries to add the contained library the second time, causing _managedLibraries.Add(library.Name.Name, library);
to raise exception.
Regarding packages, here’s what they would look like if following instructions:
Lib1
lib\
lib1.dll
Lib2
lib\
lib1.dll
lib2.dll
And yes, it’s a pretty exotic case. But since NuGet will support multiple libraries in one lib\
hive, these packages exist out there, and you’ll see them fail.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (6 by maintainers)
A PR would be great. Here are some of the changes I would make to enable this:
public System.Version FileVersion { get; set; }
This value should match AssemblyFileVersionAttributepublic System.Version AssemblyVersion { get; set; }
, maps the version in assembly identitySince setup is a bit time-consuming, I’ve made you a repro.
Clone this
https://github.com/per-samuelsson/ReproPluginsIssue
and CD into
src
, and executeRun.bat
.The app depend on those two generated packages (via
App1\Nuget.config
) and will load itself usingPluginLoader.CreateFromAssembly
, and you should see it fail.