question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PluginLoader.CreateFromAssemblyFile fail when dependency is in two packages

See original GitHub issue

Describe 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:

  1. Create a library Lib1 (e.g dotnet new classlib). Package it.
  2. Create another library, Lib2, and package it, but include Lib1.dll in that package too.
  3. Create an application referencing both packages (e.g dotnet new console). (I used a local feed and a NuGet.config)
  4. 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:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
natemcmastercommented, Nov 3, 2018

A PR would be great. Here are some of the changes I would make to enable this:

  • Don’t throw from AssemblyLoadContextBuilder.AddManagedLibrary when duplicate libraries are added. Internally, create a dictionary which varies by name and version.
  • Add two properties to ManagedLibrary
    • public System.Version FileVersion { get; set; } This value should match AssemblyFileVersionAttribute
    • public System.Version AssemblyVersion { get; set; }, maps the version in assembly identity
  • When there are assemblies with the same name, resolve the higher assembly version and higher file version if assembly versions match.
  • Populate the version info when reading from deps.json (not sure if Microsoft.Extensions.DependencyModel provides API for this or not)
1reaction
per-samuelssoncommented, Nov 1, 2018

Since 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 execute Run.bat.

The app depend on those two generated packages (via App1\Nuget.config) and will load itself using PluginLoader.CreateFromAssembly, and you should see it fail.

Read more comments on GitHub >

github_iconTop Results From Across the Web

.NET Core Plugins
The API in this package wrangles the complexity through a feature called 'load contexts'. ... Problem 2 - dependency mismatch.
Read more >
DotNetCorePlugins
This project provides API for loading .NET Core assemblies dynamically, executing them as extensions to the main application, and finding and isolating the ......
Read more >
An assembly specified in the application dependencies ...
I solved it by downgrading all my Entityframework packages to 2.0.0 instead of ... To solve the first half of the error message,...
Read more >
ViLA - Control your Virpil LEDs from in-game events!
I keep getting this error and I cannot for the life of me figure it out. It appears to be calling for "DcsBiosReader.dll"...
Read more >
Create a .NET Core application with plugins
An AssemblyDependencyResolver is used to resolve the dependencies of the plugin. The tutorial correctly isolates the plugin's dependencies ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found