Why do I receive unhandled exception of type 'System.Ty​peInitiali​zationExce​ption' when using .Net Assembly in C# code?

3 ビュー (過去 30 日間)
I am following an example given on MathWorks documentation page-
to create a .NET assembly. However, when I compile my C# code, it throws the exception:
An unhandled exception of type 'System.TypeInitializationException' occurred in MainApp.exe.
Specifically, the inner exception looks like the following:
{System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at MathWorks.MATLAB.NET.Arrays.MWArray.mclmcrInitialize2(Int32 primaryMode)
at MathWorks.MATLAB.NET.Arrays.MWArray..cctor()
--- End of inner exception stack trace ---
at MathWorks.MATLAB.NET.Utility.MWMCR..cctor()
--- End of inner exception stack trace ---
at makesquare.MLTestClass..cctor()}
How can I resolve this?

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 7 月 19 日
編集済み: MathWorks Support Team 2024 年 7 月 19 日
The Visual Studio has to be of 64-bit to run a 64-bit DLL. By default Visual Studio is a 32-bit application and while installing it you can check the option for 'x64'. 
To fix the issue, go to Visual Studio
Configuration Manager
, change the platform from 
Any CPU
 to 
x64
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeploy to .NET Applications Using MWArray API についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by