Dependencies of dinamically loaded .dll are not found [Answered]

Aalkasel8/25/2022
Hi everyone,
I've an ASP.NET Core 6 web app where I have a main project "A" that, if certain conditions are meet, load dinamically an assembly B.dll. Now, let's say B depends upon some nuget package C (has a static reference to it). When, after B assembly has been loaded dinamically and during its code execution a class belonging to C is encountered, the program crashes since C is not found.
I've noticed that, if I add to project A a static reference to C, everything works fine.

Is there a way to fix this behavior without me having to add to project A static references to ALL dependencies of ALL the assemblies I want to load dinamically? Thanks
Aalkasel8/25/2022
Actually I was able to fix .dll dependencies using this article
https://www.codeproject.com/Articles/1194332/Resolving-Assemblies-in-NET-Core?msg=5895057#xx5895057xx

I still miss how to do the same for nuget dependencies
CCisien8/25/2022
Download the nuget, extract it, load the dll. You wont necessarily know from the assembly being loaded what nuget package its in
CCisien8/25/2022
Blindly installing nugets is rather dangerous
Aalkasel8/25/2022
Ok, thanks
MMMayor McCheese8/25/2022
You might want to look a custom assembly load contexts as well
Ttebeco8/26/2022
/close
Ttebeco8/26/2022
(done for you)
AAccord8/26/2022
✅ This post has been marked as answered!