views:

17

answers:

1

Hello,

I'm working on Windows 7 with Visual Studio 2008.

I have a .NET assembly that makes calls into a native DLL with P/Invoke. I have set up a separate .NET unit test project in my Visual Studio solution that tests the assembly by making various calls into it. However, when the unit test makes a call into the assembly, and the assembly makes a call using P/Invoke, it can't find the native DLL.

When I write a standalone .NET console application, there is no problem. The assembly can use P/Invoke and find the DLL successfully.

I can make the unit test work by calling LoadLibrary with the absolute path of the DLL before using the assembly. However, this approach is ugly and requires an absolute path - which will be problematic for other users.

In short, my question is - how can I specify or amend the DLL search path that is being used when a Visual Studio unit test is being executed?

Any help will be greatly appreciated.

Regards, Dan

+1  A: 

It sounds like the problem is that your native DLL is not being deployed with your unit test DLLs. This is not an uncommon problem since managed DLL's have no reference to native ones in metadata and hence deployment packages don't know to deploy them.

The most appropriate solution is to fix deployment as opposed to changing the DLL search paths. This is a unit test specific problem though. Can you tell us what framework you're using so we can help you out?

JaredPar