How to fix NET C# System.TypeInitializationException using a DLL built by Matlab on 64bit Windows 8?
조회 수: 5 (최근 30일)
이전 댓글 표시
I'm not able to create an application on my Computer that references a .NET Assembly built using Matlab Builder NE. I'm on Windows 8 64bit, have a 64bit Matlab 2013a and I'm using Visual Studio 2012.
I followed the instructions in the Video for the makeSqr example: http://www.mathworks.de/videos/using-matlab-builder-ne-68758.html
It all works fine except I', missing the Mathworks .NET MWArray API in the GAC list of assemblies. I manually add a reference to D:\Program Files\MATLAB\MATLAB Compiler Runtime\v81\toolbox\dotnetbuilder\bin\win64\v2.0\MWArray.dll
The program compiles fine, but Initializing my class obj = new MLTest();
i get the following exception: System.TypeInitializationException wurde nicht behandelt. HResult=-2146233036 Message=Der Typeninitialisierer für "com.demo.MLTest" hat eine Ausnahme verursacht. Source=demo TypeName=com.demo.MLTest StackTrace: bei com.demo.MLTest..ctor() bei BuilderNEMainApp.Program.Main(String[] args) in c:\Users\Irgenfs\Documents\Visual Studio 2012\Projects\BuilderNEMainApp\BuilderNEMainApp\Program.cs:Zeile 33. bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() bei System.Threading.ThreadHelper.ThreadStart_Context(Object state) bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bei System.Threading.ThreadHelper.ThreadStart() InnerException: System.TypeInitializationException HResult=-2146233036 Message=Der Typeninitialisierer für "MathWorks.MATLAB.NET.Utility.MWMCR" hat eine Ausnahme verursacht. Source=demo TypeName=MathWorks.MATLAB.NET.Utility.MWMCR StackTrace: bei com.demo.MLTest..cctor() InnerException: System.TypeInitializationException HResult=-2146233036 Message=Der Typeninitialisierer für "MathWorks.MATLAB.NET.Arrays.MWArray" hat eine Ausnahme verursacht. Source=MWArray TypeName=MathWorks.MATLAB.NET.Arrays.MWArray StackTrace: bei MathWorks.MATLAB.NET.Utility.MWMCR..cctor() InnerException: System.BadImageFormatException HResult=-2147024885 Message=Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B) Source=MWArray StackTrace: bei MathWorks.MATLAB.NET.Arrays.MWArray.mclmcrInitialize2(Int32 primaryMode) bei MathWorks.MATLAB.NET.Arrays.MWArray..cctor() InnerException:
Any ideas how to fix this?
댓글 수: 0
답변 (1개)
Friedrich
2013년 11월 22일
Hi,
sounds like a bittedness issues. Is your VS 2012 Project configured as x64 project? If not, please do so and recompile.
댓글 수: 2
Friedrich
2013년 11월 25일
"Es wurde versucht, eine Datei mit einem falschen Format zu laden. "
Indicates some bittedness issue. Can you run a compiled exe (compiled with MATLAB compiler directly) on that machine? If yes, can you try setting up a C/C++ project and incoorperate a DLL compiled with MATLAB COmpiler (see the matrixdriver example in the doc) and see if that works.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!