Unit test using Visual Studio 2008

I am trying to create a Unit test using Visual Studio 2008.
Here is my simple C# class and test.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.opalkelly.frontpanel;

namespace FPGAUnitTesting
public class FPGATest
okCUsbFrontPanel ok;

    public void Run()
        ok = new okCUsbFrontPanel();

public void TestMethod1()
FPGATest tst = new FPGATest();

When I run this test in debugger I get a TypeInitializationException

Error Message:
Test method OKTestProject.OKTest.TestMethod1 threw exception: System.TypeInitializationException: The type initializer for ‘com.opalkelly.frontpanel.libFrontPanelPINVOKE’ threw an exception. —> System.TypeInitializationException: The type initializer for ‘SWIGExceptionHelper’ threw an exception. —> System.DllNotFoundException: Unable to load DLL ‘libFrontPanel-pinv’: The specified module could not be found. (Exception from HRESULT: 0x8007007E).

Error Stack Trace:
com.opalkelly.frontpanel.libFrontPanelPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_libFrontPanel(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
FPGAUnitTesting.FPGATest.Run() in C:\Documents and Settings\agilesem\Desktop\1.7\CSGui\mySEM\FPGAUnitTesting\FPGATest.cs: line 15
OKTestProject.OKTest.TestMethod1() in C:\Documents and Settings\agilesem\Desktop\1.7\CSGui\mySEM\OKTestProject\OKTest.cs: line 67

I could not figure out why ‘libFrontPanel-pinv’ could not be found. I guess this message is misleading.
Any suggestion what could be wrong?

Where is the DLL located?
Where is your executable located?
What working directory is your executable started in?

A copy of all four dlls FPGAUnitTesting.dll, OKTestProject.dll, libFrontPanel-csharp.dll and libFrontPanel-pinv.dll are in OKTestProject\bin\Debug. It also contains OKTestProject.vshost.exe and pdb files.

What working directory is your executable started in?

My understanding is that the starting directory is /bin/debug. If I deliberately select this directory in the project properties, this does not change anything. The output of the unit test application is a dll.

Sorry, this may not be the best forum for figuring this out. I think it would be best to talk to the MSDN folks or C# experts on this.

Maybe, you could try to reproduce my problem. It takes 5 minutes.

Dimitri-- We don’t have this problem producing executables. The samples work fine for us here. Do you have success building the samples?

Although we could probably reproduce your results in 5 minutes, that wouldn’t go far to producing a solution because we’re not familiar with the Visual Studio C# unit testing. In the end, we’d probably follow the same route that we’re recommending – contact Microsoft, review information on MSDN, or consult others regarding C# unit testing.

We can certainly do this, but it will take somewhat longer than just reproducing the failing results.

We also do not have problems with your C# libraries except when we use them for Unit testing. Thank you for your reply. I will follow your advise.