Thanks for the reply Anders. I was using the test project and I was able to solve the problem on my own. The error was
(System.BadImageFormatException)A System.BadImageFormatException was thrown. An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
and I fixed it by changing in the Visual Studio project properities\build target platform option to 32 bit. Hope this can help if someone has the same problem.