Fexty
Very specific question about AssemblyLoadContext and Assembly Resolution
So a bit of context: I'm developing a plugin system for modding a game (hopefully this is allowed here).
It has a native dll which hosts the .NET 8 runtime using hostfxr. Then there are 2 assemblies A.dll and B.dll
- A.dll is loaded into the default ALC by the native dll using
hdt_load_assembly
- B.dll is loaded into a unique custom ALC created by A.dll
- B.dll then loads plugins into their own custom ALCs (one ALC per plugin)
Inside all of those ALCs I'm using AssemblyDependencyResolver
to resolve dependencies, or I delegate it to the "parent" ALC if it can't be resolved, which eventually ends up with the Default ALC.
Now I tried creating a WPF assembly and I'm having two issues:
1. Since AssemblyDependencyResolver
doesn't resolve framework assemblies as far as I understand it, I just try calling AssemblyLoadContext.Default.LoadFromAssemblyName
when one of these is requested.
However the default ALC fails to resolve these assemblies for some reason. (Throws FileNotFoundException
)
2. I tried brute-forcing it by simply manually resolving the path to C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\8.0.1\ref\net8.0
(which is where the WPF assemblies seem to be installed for me) and calling AssemblyLoadContext.Default.LoadFromAssemblyPath
directly. However doing this I get a BadImageFormatException
.
Here is the exact exception thrown:
System.BadImageFormatException: Could not load file or assembly 'PresentationFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Reference assemblies cannot be loaded for execution. (0x80131058)For reference: I have also attempted this with WinForms. It also had the first issue of not being able to resolve the dependencies, but for that the brute force approach worked. I am honestly stumped here and would really appreciate some help. I can provide source code as well if necessary. 🙂
5 replies
Can't install tools with `dotnet tool` command
When I try to install a dotnet tool from the terminal I always get an error. Example:
dotnet tool install docfx -g
Running this always gives me an exception with the following stacktrace:
This happens with all packages I try to install. It's telling me something about source mappings, but I don't understand if I have it configured incorrectly, or if I straight up need to disable it or something?
Very lost.11 replies