I found the problem. My project was compiling for "any cpu" while it had to be x64.
C# return an error when trying to use Matlab function generated with compiler SDK
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everyone,
I am trying to discover the Matlab Compiler SDK. So I used a function that I previously coded and removed all inputs and outputs to have it look like :
function traj2D_plot5()
This function does some calculation then generates a csv file (with csvwrite) and displays a plot3 and a scatter3 figure.
With the Matlab Compiler SDK I generated the .Net files from this function. Which gave me two dlls located in the for_redistribution_files_only folder:
traj2D_plot5.dll traj2D_plot5Native.dll
I referenced these two dlls in my C# project as long as the Matlab Runtime.
I then went in the for_testing folder to get the traj2D.cs file (I specified the class name as traj2D in the Matlab Compiler) that I added in my project as well. I was (and am still) surprised to see the C# files and the dlls did not really look like the video tutorial but there is a constructor in the traj2D.cs file so I went for it anyway.
I have a button designed in my C# project so in that button I wanted to call the class and launch the function kind of like in the video tutorial. So I wrote two simple lines of C# code :
traj2D_plot5.traj2D traj = new traj2D_plot5.traj2D();
traj.traj2D_plot5();
However, if everything compiles in my project when I click my button and it calls the first line my system returns this error :
System.TypeInitializationException : 'An exception has been raised by the type initialiser for 'traj2D_plot5.traj2D'.'
BadImageFormatException : Attempt of loading a program with incorrect format. (Exception de HRESULT : 0x8007000B)
So I have no idea how to simply run the matlab function and I am having trouble finding complete documentation on the subject. So if anyone can help me on this problem I will be very much thankful.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!