Matlab generated dll is calling in asp.net application

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

 Accepted 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.

11 Comments

I am using matlab R2016b . Sir i done it but this error is occured now. An unhandled exception of type 'System.TypeInitializationException' occurred in MWArray.dll
Which type of project are you using? ASP.NET Web application or Windows Forms application?
Could you confirm you did uncheck prefir 32 bit in the project settings?
no sir i can't check it i am using Asp.net web application
Sir i uncheck prefir 32 bit in the project setting but again error occur
"Could not load file or assembly 'projectwebsite' or one of its dependencies. An attempt was made to load a program with an incorrect format."
I see, it's because Visual Studio uses 32 bit version of IIS Express, so, 64 bit of ASP.NET project cannot be run. From Visual Studio, go to Tools -> Options -> "Projects and Solutions" -> "Web Projects" and check "Use the 64bit version of IIS Express for web sites and projects".
Sir i can't found this option in web project option instead this option is available "Use IIS Express for new file-based websites and projects "
Are you using Visual Studio 2010 or earlier? Is it possible to update it to 2013 or later because it supports 64bit of IIS Debugging.
Sir i m using visual studio 2012
OK, I've tested using Visual Studio 2012. It cannot select 64 bit of IIS Express, but there's a workaround.
You need to enable IIS first.
Launch Visual Studio 2012 as a administrator, and open your Web Site. Then in Solution Explorer, right click and click "Publish Web Site". Input the Server hostname and Site name Project Name so on. I'm attaching a screenshot. Compiler_SDK_NET_ASP is a Web Site name in this case. After publishing, you can run your ASP.NET application in the web browser without an error.
Hope this work!
Sir when i create dll of the function which only add two number it works fine but when i create dll of the function that consist of matlab built in function like imread etc then when we connect with asp.net then error occured that "The installed matlab runtime is not compatable with the application " how i solve it?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!