© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•5mo ago•
25 replies
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>
    <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
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'
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
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

C# - WinForms Single Executable File (Folder)
C#CC# / help
2y ago
❔ Can't find dll reference assemblies
C#CC# / help
3y ago
❔ Program can't find folder
C#CC# / help
3y ago