Type initializer for 'com.opalkelly.frontpanel.libFrontPanelPINVOKE' threw an except

I am trying to program for the XEM5010 using Visual Studio Express 2010 using VB on Windows 7 64-bit. I used the libFrontPanel-csharp.dll as a reference and included libFrontPanel-pinv.dll in the project so that it would get copied to the destination folder. I also tried it with a C# program and got the same exception.

When I try to run the line:

xem = New okCFrontPanel

I got the following exception

System.TypeInitializationException was caught
Message=The type initializer for ‘com.opalkelly.frontpanel.libFrontPanelPINVOKE’ threw an exception.
at com.opalkelly.frontpanel.libFrontPanelPINVOKE.new_okCFrontPanel()
at com.opalkelly.frontpanel.okCFrontPanel…ctor()
at VBDPD.MainForm.buttonInitialize_Click(Object sender, EventArgs e) in C:\Users\Glen\Documents\work\ETADevices\Software\VBDPD\VBDPD\MainForm.vb:line 237
InnerException: System.TypeInitializationException
Message=The type initializer for ‘SWIGExceptionHelper’ threw an exception.
at com.opalkelly.frontpanel.libFrontPanelPINVOKE.SWIGExceptionHelper…ctor()
at com.opalkelly.frontpanel.libFrontPanelPINVOKE…cctor()
InnerException: System.BadImageFormatException
Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at 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)
at com.opalkelly.frontpanel.libFrontPanelPINVOKE.SWIGExceptionHelper…cctor()

Any help would be appreciated


I fixed it by uninstalling FrontPanel and installing the 32-bit version

Could this be because I am on an AMD PC?


Which version of FrontPanel were you using?

I’m getting this problem too in C# 2010 using windows 7 x64. The line that generates the exception is:

m_dev = new okCFrontPanel();

the version of libFrontPanel-csharp.dll being included in the project is 1.0.4308.23525.

I’ve also tried installing 32 and 64 bit versions of front panel.

More detail:

I can compile the DESTester example no problem, but when I port this code into a new project I start getting this error.


The appears to be a problem with compiling in debug mode. When I select Solution->Properties->Configuration->Debug I get the exception, when I select release code, it appears that it runs no problem.

Interesting that I have it vice versa. On Windows7-64bit, VS 2010/c# it works if I compile it in Debug mode, but not in Release ( I have FrontPanel 4.0.6) .