C#C
C#3mo ago
peppy

Single-file executable can't find dependency DLL in its folder

The intent is to publish a single-file executable which loads its runtime/native dependencies dynamically from the folder it is located in.
I have ensured that those versions of the dependencies are placed in the same folder as the output.

The project file is:
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net9.0</TargetFramework>
        <RuntimeIdentifier>win-x86</RuntimeIdentifier>
        <PublishSingleFile>true</PublishSingleFile>
        <SelfContained>false</SelfContained>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Hexa.NET.ImGui.Backends" Version="1.0.17.4">
            <ExcludeAssets Condition="'$(Configuration)'=='Release'">runtime;native</ExcludeAssets>
            <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
        </PackageReference>
        <PackageReference Include="TerraFX.Interop.Windows" Version="10.0.26100.2">
            <ExcludeAssets Condition="'$(Configuration)'=='Release'">runtime;native</ExcludeAssets>
            <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
        </PackageReference>
    </ItemGroup>

yet at runtime, though TerraFX.Interop.Windows.dll is in the same folder (v. attached image)
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'TerraFX.Interop.Windows, Version=10.0.26100.2, Culture=neutral, PublicKeyToken=35b01b53313a6f7e'. The system cannot find the file specified.
File name: 'TerraFX.Interop.Windows, Version=10.0.26100.2, Culture=neutral, PublicKeyToken=35b01b53313a6f7e'


There is no issue in Debug. The dependencies are placed in the output folder by an earlier-building project which is also win-x86, has the same PackageReferences, down to the version (minus the ExcludeAssets bit).
Is there any obvious reason why this would occur that I am missing?
image.png
Was this page helpful?