Open Closed

Loading multiple versions of the same Library (Assembly) #5678


User avatar
0
daniel.hagn@vireq.com created
  • ABP Framework version: v7.1.0
  • UI Type: Angular
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Dear Volosoft team,

We have a problem loading modules as plug-ins in ABP. The application looks like this:

Core-(shared)-library: A library (nuget package) that is used in the main application and all plugins. Main Application: The main application built with ABP. Plugins: ABP plugins loaded with "PlugInSources...".

Folder structure (Build):

  • Main-Application.exe
  • Core-(Shared)-Library.dll (version 1.0.0)
  • Modules (Folder)
    • Plugin 1 (Folder)
      • Plugin1.dll
      • Core-(Shared)-Library.dll (version 1.0.1)
    • Plugin 2 (Folder)
      • Plugin2.dll
      • Core-(Shared)-Library.dll (version 1.0.2)
    • Plugin 3 (Folder)
      • Plugin3.dll
      • Core-(Shared)-Library.dll (version 1.0.3)

Now we have the following problem:

At application startup, the main application loads its dependencies, in this case the Core-(Shared)-Library.dll in version 1.0.0. When ABP tries to load the plugins, it tries to load their dependencies as well. If the versions of the dependencies are all the same (always version 1.0.0), there's no problem. But we can't guarantee that this is always the case. (See Diagram)

Is there a way to load multiple versions (1.0.0, 1.0.1, 1.0.2, 1.0.3) of the Core-(Shared)-Library assembly?

What we have already tried: We tried attaching to the AppDomain.CurrentDomain.AssemblyResolve event handler, but because the dependency was already loaded (only with an older version), this event handler never gets triggered.

Best Regards.


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Is there any error stack?

  • User Avatar
    0
    daniel.hagn@vireq.com created

    Hi,

    Is there any error stack?

    We get following Error in the Log-File:

    [13:10:52 INF] Starte Main-Appplication.
    [13:10:52 INF] - Starte Anwendung auf 'https://localhost:44321'
    [13:10:53 FTL] Could not load file or assembly 'Core-(Shared)-Library, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null'.
    

    The Applicationname (Main-Application), Assemblyname (Core-(Shared)-Library) and Assemblyversion (1.0.1.0) got changed to match the Example.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    ABP uses the AssemblyLoadContext to load assembly.

    You can check the Microsoft's document: https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/understanding-assemblyloadcontext https://learn.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=net-7.0

    It is not possible to load multiple versions of the runtime in a single process.

    https://learn.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=net-7.0#technical-challenges The document mentions that you can't load different versions in a single process.

    You can try to use resolving event instead of AppDomain.CurrentDomain.AssemblyResolve https://learn.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext.resolving?view=net-7.0#system-runtime-loader-assemblyloadcontext-resolving

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11