MATLAB: Matlab generated dll is calling in asp.net application

dll callingMATLAB Compiler SDK

Recently I've been starting with Asp.net, particularly Web Form application. And in the application, I need to reference a dll produced by Matlab deploytool (including a .m function I wrote myself). I copied all relevant dlls to the Bin directory, add reference in the application and using the corresponding namespace. The compiler works fine but a TypeInitializationException was thrown in runtime when trying to initialize an instance of my matlab class.
BTW, in a Windows Form application it works fine amazingly, but not in Web Form applcation. Is there anything I missed when calling a matlab dll? e.g. Add XML comment in Web.config ?
Here is the key code from where the exception was thrown:
using MathWorks.MATLAB.NET.Arrays; using MathWorks.MATLAB.NET.Utility; using diseases; //this is the namespace of urinary_bladder created by library compiler
MWArray [] value = new MWArray[8]; // This statement works well
urinary_bladder ub = new urinary_bladder(); // A 'TypeInitializationException' was thrown here

Best Answer

What's version of MATLAB do you use?
Possibly you need to confirm that target CPU is 64 bit in Visual Studio. From Project menu, go to WebApplicationName Properties, click "Build" tab and change Platform target to x64.