Fexty
Fexty
CC#
Created by Fexty on 1/22/2024 in #help
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
CC#
Created by Fexty on 12/7/2023 in #help
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:
Unhandled exception: Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageInstallerException: Package Source Mapping is enabled, but no source found under the specified package ID: docfx. See the documentation for Package Source Mapping at https://aka.ms/nuget-package-source-mapping for more details.
at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.LoadNuGetSources(PackageId packageId, PackageSourceLocation packageSourceLocation, PackageSourceMapping packageSourceMapping)
at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.GetBestPackageVersionAsync(PackageId packageId, VersionRange versionRange, PackageSourceLocation packageSourceLocation)
at Microsoft.DotNet.Cli.ToolPackage.ToolPackageDownloader.<>c__DisplayClass8_0.<InstallPackage>b__0()
at Microsoft.DotNet.Cli.TransactionalAction.Run[T](Func`1 action, Action commit, Action rollback)
at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.Execute()
at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
Unhandled exception: Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageInstallerException: Package Source Mapping is enabled, but no source found under the specified package ID: docfx. See the documentation for Package Source Mapping at https://aka.ms/nuget-package-source-mapping for more details.
at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.LoadNuGetSources(PackageId packageId, PackageSourceLocation packageSourceLocation, PackageSourceMapping packageSourceMapping)
at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.GetBestPackageVersionAsync(PackageId packageId, VersionRange versionRange, PackageSourceLocation packageSourceLocation)
at Microsoft.DotNet.Cli.ToolPackage.ToolPackageDownloader.<>c__DisplayClass8_0.<InstallPackage>b__0()
at Microsoft.DotNet.Cli.TransactionalAction.Run[T](Func`1 action, Action commit, Action rollback)
at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.Execute()
at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
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