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.

leppie
  • 115,091
  • 17
  • 196
  • 297
Ante
  • 96
  • 9
  • There is nothing in VS that makes it automatically delete DLLs when you stop debugging. Impossible to guess what might do this. Try using attrib.exe to make the file readonly after building. Something ought to go bang! when whatever program is doing this can't delete the file anymore. – Hans Passant May 07 '13 at 16:00
  • DLLs are not deleted after stop debugging, on the contrary they are there. But when I start debugging again then they will be deleted. If I add readonly on DLLs, then everything works, files are not deleted. But then on rebuild VS can't delete them, i.e. **Unable to delete file "D:\project\source\Branch-AT\unmanaged.dll". Access to the path 'D:\project\source\Branch-AT\unmanaged.dll' is denied.** – Ante May 08 '13 at 09:34
  • Solved: http://stackoverflow.com/questions/12386523/visual-studio-not-copying-content-files-from-indirectly-referenced-project – Ante Jun 18 '13 at 08:57

1 Answers1

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.