How to invoke a .NET-method which expects a .NET-struct as parameter?
2 views (last 30 days)
Show older comments
Hello,
is this possible at all in Matlab? I have a .NET assembly with a method that expects a .NET struct as parameter. I can't figure out how to create an appropriate struct for the method. I always get the error
"No method 'TestNETNameSpace.TestNETClass.passStructToMe' with matching signature found."
with this Matlab code or my other attempts:
asmbl = NET.addAssembly('C:\Test\testNETAssembly.dll');
import TestNETNameSpace.*
result1 = TestNETClass.passIntToMe(42); % This works fine.
% Question: How to make this right?
Matlabstruct.stringInStruct = "hello";
Matlabstruct.doubleInStruct = 12.5;
result2 = TestNETClass.passStructToMe(Matlabstruct); % This throws an error.
This is the C# -code of my assembly testNETAssembly.dll.
namespace TestNETNameSpace
{
public static class TestNETClass
{
public struct TestNETStruct
{
public string stringInStruct;
public double doubleInStruct;
}
public static string passStructToMe(TestNETStruct str)
{
return str.stringInStruct;
}
public static int passIntToMe(int i)
{
return i;
}
}
}
0 Comments
Answers (1)
Mohammad Sami
on 23 Apr 2025
Edited: Mohammad Sami
on 23 Apr 2025
You can follow the type converstion between Matlab and .NET here
In particular your .NET function would need to accept the following type of variable.
MathWorks.MATLAB.Types.MATLABStruct
MathWorks.MATLAB.Types.MATLABStruct[]
MathWorks.MATLAB.Types.MATLABStruct[,,...]
If you are trying to use a third parties code, I assume you will then have to write your own wrapper functions in .NET which covert your matlab data into the type required for your third party library to work.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!