MATLAB Answers


From MATLAB to ASP.NET Web Forms Application/Web deployment - How to solve 'System.Ty​peInitiali​zationExce​ption' error?

Asked by Marcus Vo on 23 Dec 2016
Latest activity Commented on by BENELMIR WALID on 29 Jan 2018
I'm trying to get a simple addition function performed within MATLAB to work on a webpage with an ASP.NET Web Forms application, purely to see if the process works.
1. I use the Library Compiler to build the 'addNumbers.dll' along with the class 'AdditionClass' to instantiate .
2. Reference the 'addNumbers.dll' along with the 'MWArray.dll' in the the C#.
3. Run the web application, but a 'System.TypeInitializationException' in App_Web_XXX.dll errors occurs once the button to perform the addition is pressed.
MATLAB R2015a, x64 Windows 10. Changing the debug configuration to x64 within VS does not seem to solve it. Any help would be greatly appreciated.
'Add' button results in exception error and breaks.
Exception Detail: System.BadImageFormatException
Oddly enough, it does work with pretty much the exact same C# code and same .dll paths, except in a Windows Forms Application rather than a Web Form. This at least proves the correct .dll files are being referenced and the code is correct (presumably).


Sign in to comment.

1 Answer

Answer by Friedrich
on 28 Dec 2016
 Accepted Answer

there are two pieces to the puzzle here. First the bittedness of the DLL you built and second the bittedness of the webserver. I assume you are using the ISS which VisualStudio starts for you when pressing play/run. Per default VS will host the 32bit ISS but you have a 64bit DLL which the webserver should load. In order to get this working you need to tell VS to start the 64bit ISS version. See here for how to do it. Basically go to Tools | Options | Projects and Solutions | Web Projects and check the "Use the 64 bit version of IIS Express…" option.


Much appreciated, this is indeed the solution - a frustratingly simple one for a problem which I found impossible to troubleshoot.

Sign in to comment.