C#C
C#7mo ago
2 replies
peppy

Dynamically loading native dependency of NuGet package fails when compiling for specific RID

I am attempting to utilize https://github.com/HexaEngine/Hexa.NET.ImGui in a project compiled for a specific RID. This NuGet package has a native dep, cimgui.dll, selected per RID.
    <PropertyGroup>
        <TargetFramework>net9.0</TargetFramework>
        <RuntimeIdentifier>win-x86</RuntimeIdentifier>
        <EnableDynamicLoading>true</EnableDynamicLoading>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Hexa.NET.ImGui.Backends" Version="1.0.15" />
    </ItemGroup>


When compiling the .NET library that uses it for a specific RID, that specific RID's version of the dependencies gets emitted next to the consuming library itself. Yet at runtime the dependency/dependencies cannot be found.

The .deps.json is a bit confusing in this regard:
"targets": {
    ".NETCoreApp,Version=v9.0": {},
    ".NETCoreApp,Version=v9.0/win-x86": {
      "fhcore/1.0.0": {
        "dependencies": {
          "Hexa.NET.ImGui.Backends": "1.0.15"
        },
        "runtime": {
          "fhcore.dll": {}
        }
      },
// ...
      "Hexa.NET.ImGui.Backends/1.0.15": {
        "dependencies": {
          "Hexa.NET.ImGui": "2.2.7",
          "HexaGen.Runtime": "1.1.18"
        },
        "runtime": {
          "lib/net9.0/Hexa.NET.ImGui.Backends.dll": {
// ...
          }
        },
        "native": {
          "runtimes/win-x86/native/ImGuiImpl.dll": {
// ...
          }
        }
      },

yet these DLLs are not under runtimes/{RID}/native or lib/net9.0/ relative to fhcore, they're right next to it. What causes this discrepancy, and is it the reason the libraries cannot be found?
Was this page helpful?