C
C#3mo ago
Mazranel

Application fails to find DLL that is in the same directory

I've added a DLL reference to my project, which compiles just fine but when the application runs it fails to find this DLL even though it's in the same directory. How would I debug this?
No description
53 Replies
Sossenbinder
Sossenbinder3mo ago
Is this a .Net Framework app by chance?
Mazranel
MazranelOP3mo ago
No, it's .NET 8
Sossenbinder
Sossenbinder3mo ago
I see! I didn't run into this error for ages. Back in .Net Framework, my go to tool for this used to be Fusion logging. However, I am not 100% sure it still works with net core / 8. What definitely should work is using something like dotnet trace to collect assembly events One sec, looking up the link
Sossenbinder
Sossenbinder3mo ago
It should provide you with some details on the probed paths So you can inspect which paths were tried for resolving the dll
Mazranel
MazranelOP3mo ago
Cool, I'll give it a shot :) Does this tool also work on Linux? Nvm, the documentation says it should
Sossenbinder
Sossenbinder3mo ago
Collection definitely works on linux yeah
Mazranel
MazranelOP3mo ago
It's only providing me with some process path information, is there a specific argument I need to pass? I'm calling it like so: dotnet-trace collect -- MAGE This is the output:
No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name Keywords Level Enabled By
Microsoft-DotNETCore-SampleProfiler 0x0000F00000000000 Informational(4) --profile
Microsoft-Windows-DotNETRuntime 0x00000014C14FCCBD Informational(4) --profile

Launching: MAGE
Process : /media/<uname>/1D8E170E787C927A/Programming/C#/MAGE/bin/Debug/net8.0/MAGE
Output File : /media/<uname>/1D8E170E787C927A/Programming/C#/MAGE/bin/Debug/net8.0/MAGE_20240911_155830.nettrace

[00:00:00:04] Recording trace 1.2387 (MB)
Press <Enter> or <Ctrl+C> to exit...

Trace completed.
Process exited with code '2'.
No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name Keywords Level Enabled By
Microsoft-DotNETCore-SampleProfiler 0x0000F00000000000 Informational(4) --profile
Microsoft-Windows-DotNETRuntime 0x00000014C14FCCBD Informational(4) --profile

Launching: MAGE
Process : /media/<uname>/1D8E170E787C927A/Programming/C#/MAGE/bin/Debug/net8.0/MAGE
Output File : /media/<uname>/1D8E170E787C927A/Programming/C#/MAGE/bin/Debug/net8.0/MAGE_20240911_155830.nettrace

[00:00:00:04] Recording trace 1.2387 (MB)
Press <Enter> or <Ctrl+C> to exit...

Trace completed.
Process exited with code '2'.
ACiDCA7
ACiDCA73mo ago
is the box2d dll in the output directory (also its dependencies) ?
Sossenbinder
Sossenbinder3mo ago
--providers Microsoft-Windows-DotNETRuntime:4
Mazranel
MazranelOP3mo ago
I tried this earlier and the result was the same unfortunately Yeah it is
Sossenbinder
Sossenbinder3mo ago
dotnet-trace collect --providers Microsoft-Windows-DotNETRuntime:4 -p <pid> should do it usually Is that the one you tried?
Mazranel
MazranelOP3mo ago
I didn't use -p, I just had it start the executable because it throws an error before I can get the process ID Trying that results in the same output
Sossenbinder
Sossenbinder3mo ago
I see - Should be fine though, the assembly loading events should be part of the default profile which also includes the DotNETRuntime provider
Sossenbinder
Sossenbinder3mo ago
Loader and binder runtime events - .NET
Learn about the .NET runtime events that collect diagnostic information specific to loader and binder ETW events, which collect information about the assembly loader and binder.
Sossenbinder
Sossenbinder3mo ago
This is what should be included
Mazranel
MazranelOP3mo ago
Is this information stored in the output report file?
Sossenbinder
Sossenbinder3mo ago
You should end up with a .nettrace file including the entire collected traces Yeah
Mazranel
MazranelOP3mo ago
I do have those, I read that you can open them with PerfView
Sossenbinder
Sossenbinder3mo ago
Yeah, PerfView or VS usually VS has pretty good integration with a lot of the dotnet diagnostic tool outputs
Mazranel
MazranelOP3mo ago
I'll have to reboot into windows real quick, but hopefully it gives some useful information :)
Sossenbinder
Sossenbinder3mo ago
dotnet-trace diagnostic tool - .NET CLI - .NET
Learn how to install and use the dotnet-trace CLI tool to collect .NET traces of a running process without the native profiler, by using the .NET EventPipe.
Sossenbinder
Sossenbinder3mo ago
It's just in the dotnet-trace docs though But I'm not familiar with that route, since I'm on windows
Mazranel
MazranelOP3mo ago
Hmm It's definitely worth a shot, it's good to know that I have multiple ways to do this if I need them
reflectronic
reflectronic3mo ago
can you send the .deps.json file in your build output
reflectronic
reflectronic3mo ago
instead of using dotnet trace i would first try export COREHOST_TRACE=1 and then running the application it should dump a bunch of stuff to the console
Mazranel
MazranelOP3mo ago
There's a lot to go through here, I'll upload a text file with the output Or not, turns out it's a separate process that's dumping that stuff to the console
reflectronic
reflectronic3mo ago
yeah, once you set it, you want to directly run your output program, not dotnet run or whatever
Mazranel
MazranelOP3mo ago
It looks like Box2DX.dll is in the output: :/media/<uname>/1D8E170E787C927A/Programming/C#/MAGE/bin/Debug/net8.0/Box2DX.dll:
Sossenbinder
Sossenbinder3mo ago
Oh, right, I forgot about the corehost_trace flag. I think there's also one to output the traces to a file instead of console if it's inconvenient?
Mazranel
MazranelOP3mo ago
Sine my terminal has a maximum backtrace size, that would be preferred. I'll see if I can find that flag
reflectronic
reflectronic3mo ago
COREHOST_TRACEFILE=path
Mazranel
MazranelOP3mo ago
GitHub
runtime/docs/design/features/host-tracing.md at main · dotnet/runtime
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps. - dotnet/runtime
Mazranel
MazranelOP3mo ago
Here's the output of that:
Mazranel
MazranelOP3mo ago
I noticed that it skipped the file exists check, is that an issue?
reflectronic
reflectronic3mo ago
can you send Box2DX.dll rename the file extension
MODiX
MODiX3mo ago
Please don't upload any potentially harmful files @Mazranel, your message has been removed
reflectronic
reflectronic3mo ago
yeah
Mazranel
MazranelOP3mo ago
Ah
reflectronic
reflectronic3mo ago
yeah, this is a terrible error message the issuse is that the DLL is compiled to target x86
Mazranel
MazranelOP3mo ago
Ah, so I'll need to switch to x86
reflectronic
reflectronic3mo ago
for whatever reason, this is the error message you get when you try and load a libary with the wrong architecture you should just switch it to AnyCPU
Mazranel
MazranelOP3mo ago
Microsoft should really make some better error messages
reflectronic
reflectronic3mo ago
i suspect Box2DX does not actually target x86 for any reason
Mazranel
MazranelOP3mo ago
I think it already is actually, at least in VS the debug mode was set to anycpu
reflectronic
reflectronic3mo ago
you might have to edit it in the csproj file or the configuration editor
Mazranel
MazranelOP3mo ago
I'll double check, if it's not anycpu I'll change it Nope, adding <PlatformTarget>AnyCPU</PlatformTarget> didn't help This is the CSPROJ
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hexa.NET.ImGui" Version="2.1.1" />
<PackageReference Include="Hexa.NET.ImGuizmo" Version="2.1.1" />
<PackageReference Include="Hexa.NET.ImNodes" Version="2.1.1" />
<PackageReference Include="Hexa.NET.ImPlot" Version="2.1.1" />
<PackageReference Include="Hexa.NET.Raylib" Version="1.0.0" />
<PackageReference Include="ini-parser" Version="2.5.2" />
<PackageReference Include="NativeFileDialogSharp" Version="0.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Raylib-cs" Version="6.1.1" />
<PackageReference Include="Sayers.SDL2.Core" Version="1.0.11" />

<Content Include="Editor\Resources\Materials\**\*.*" CopyToOutputDirectory="Always" TargetPath="Resources\Materials\%(Filename)%(Extension)" />
<Content Include="Editor\Resources\Shaders\**\*.*" CopyToOutputDirectory="Always" TargetPath="Resources\Shaders\%(Filename)%(Extension)" />
<Content Include="Editor\Resources\Skybox\**\*.*" CopyToOutputDirectory="Always" TargetPath="Resources\Skybox\%(Filename)%(Extension)" />
<Content Include="Editor\Resources\Icons\**\*.*" CopyToOutputDirectory="Always" TargetPath="Resources\Icons\%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<None Remove="Shared\Libraries\Box2DX.dll" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Shared\Libraries\Box2DX.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Reference Include="Box2DX">
<HintPath>Shared\Libraries\Box2DX.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hexa.NET.ImGui" Version="2.1.1" />
<PackageReference Include="Hexa.NET.ImGuizmo" Version="2.1.1" />
<PackageReference Include="Hexa.NET.ImNodes" Version="2.1.1" />
<PackageReference Include="Hexa.NET.ImPlot" Version="2.1.1" />
<PackageReference Include="Hexa.NET.Raylib" Version="1.0.0" />
<PackageReference Include="ini-parser" Version="2.5.2" />
<PackageReference Include="NativeFileDialogSharp" Version="0.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Raylib-cs" Version="6.1.1" />
<PackageReference Include="Sayers.SDL2.Core" Version="1.0.11" />

<Content Include="Editor\Resources\Materials\**\*.*" CopyToOutputDirectory="Always" TargetPath="Resources\Materials\%(Filename)%(Extension)" />
<Content Include="Editor\Resources\Shaders\**\*.*" CopyToOutputDirectory="Always" TargetPath="Resources\Shaders\%(Filename)%(Extension)" />
<Content Include="Editor\Resources\Skybox\**\*.*" CopyToOutputDirectory="Always" TargetPath="Resources\Skybox\%(Filename)%(Extension)" />
<Content Include="Editor\Resources\Icons\**\*.*" CopyToOutputDirectory="Always" TargetPath="Resources\Icons\%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<None Remove="Shared\Libraries\Box2DX.dll" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Shared\Libraries\Box2DX.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Reference Include="Box2DX">
<HintPath>Shared\Libraries\Box2DX.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
reflectronic
reflectronic3mo ago
to be clear, i mean on the Box2DX project
Mazranel
MazranelOP3mo ago
Ah The target framework for the Box2DX project is netstandard2.0, I dunno if that'll cause issues or not
reflectronic
reflectronic3mo ago
that is fine you just need it to not make an x86 DLL
Mazranel
MazranelOP3mo ago
Awesome, it runs now! I just need to make sure it's actually working Does this server have a way to mark posts as solved?
Want results from more Discord servers?
Add your server