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!