Unmanaged DLL in Visual Studio 2012 C# project - DllNotFoundException after Build

0

I've added an unamanaged dll in project OldTesters using Add Existing File. I've also set BuildAction = Content and Copy to Output Directory = Copy if newer. I'm using some functions from unmanaged dll in OldTesters project via [DllImport("unamanged.dll")]

OldTesters is .NET project that I've referenced in my main project using Add Reference.

The problem is when I rebuild application everything works fine, but then I close app, and then click on start, it throws me DllNotFoundException

Unable to load DLL 'unmanaged.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I've noticed that Visual Studio deleted unmanaged.dll from bin directory.

If I rebuild OldTesters project then it will work. But it is annoying always to rebuild OldTesters, cause I do not add any changes in that project. To prove that, if I click on Build, I will get:

========== Build: 0 succeeded, 0 failed, 6 up-to-date, 0 skipped ==========

because there are no changes in the project.When I run the app I get the same exception.

visual-studio
visual-studio-2012
asked on Stack Overflow May 7, 2013 by Ante • edited May 7, 2013 by leppie

1 Answer

0

Although this is VERY old, I just stumbled across the same problem and found the following solution: just copy all the dlls that are "deleted" to your current project in VS, then they are copied whenever this project is created. So in your case you just open the project OldTesters, click on the unmanaged dll, copy and then paste it into the project that your other project.

answered on Stack Overflow Oct 12, 2018 by pacopericolo

User contributions licensed under CC BY-SA 3.0