I created a netcoreapp2.1 console application and wanted to use a native dll.
Solution structure:
-test
--dependecy1.dll (needed by some.dll)
--depedency2.dll (needed by some.dll)
--Program.cs
--some.dll
--test.csproj (netcoreapp2.1 console application)
To have the dlls copied in debug, I marked them with:
<None Update="some.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="dependecy1.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="dependecy2.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
I wrote a static method and used DllImport("some.dll"):
[DllImport("some.dll")]
public static extern ulong do_dll_stuff(int arg1);
Then I called this method in the main method, and it worked!
Now I want to move this code in a class library (netstandard2.0). I created a class library project, moved the files into the new project, moved the code into the NativeMethods.cs and referenced it in my application above, nothing fancy. I also made sure the dlls are copied into the debug folder, in the same way as seen above.
Solution structure:
-test
--Program.cs
--test.csproj (netcoreapp2.1 console application)
-native
--dependecy1.dll (needed by some.dll)
--depedency2.dll (needed by some.dll)
--native.csproj (netstandard2.0 class library, referenced by test.csproj)
--NativeMethods.cs
--some.dll
If I now run* my application, I get:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'some.dll' or one of its dependencies
. I checked and all 3 dlls are inside test\bin\Debug\netcoreapp2.1
What am I missing?
edit 1:
* I use the run button in my IDE. As far as I see, this calls dotnet test/bin/Debug/netcoreapp2.1/test.dll
, which was the standard configuration after I created a new console application. The build process doesn't produce an exe when debugging, and the test.dll can be used with dotnet, as an exe would be used.
https://stackoverflow.com/a/44074296/8862152
edit 2: I uploaded some files in a github repository. Take note, these are not the real dlls (not allowed to upload those), just text files. But it's good enough to build the sln and see the folder structure. https://github.com/alexandrosntak/cant-locate-dll-example