Calling class and methods from C# dll
6 views (last 30 days)
Show older comments
I'm trying to call the method from matlab, but getting error as 'Too many input arguments'.
My matlab code is
pulsar = PulsarWebClientLibrary.Pulsar("http://svt_neldah/api/");
pulsar.Client.SendCommand1(PulsarWebClientLibrary.PulsarCommands.Poke, DLDetailsEvent);
My 2 C# codes is
namespace PulsarWebClientLibrary
{ public class Pulsar : IPulsar, IDisposable
{ internal static string url;
protected internal Client pulsarClient;
public Pulsar(string url1)
{
url = url1;
Client = new Client(url);
}
}
using PulsarWebClientLibrary;
public class Client
{
public async Task SendCommand1(string command, EventHandler<object> eventHandler, string parameter = "")
{
Progress<object> progress = new Progress<object>();
progress.ProgressChanged += eventHandler;
Task t = GetAsync(command, progress, parameter);
await t;
return;
}
}
0 Comments
Answers (1)
Ronit
on 11 Jun 2025
Edited: Ronit
on 11 Jun 2025
The issue you are encountering is due to how MATLAB handles .NET interop, especially with methods that have default parameters. The issue is that MATLAB does not support default parameters when calling .NET methods. Default parameters in C# are resolved at compile-time, but MATLAB requires you to explicitly provide all parameters when invoking the method.
You need to pass all three parameters explicitly when calling the method from MATLAB, even if you are using the default value for parameter:
pulsar.Client.SendCommand1(PulsarWebClientLibrary.PulsarCommands.Poke, DLDetailsEvent, "");
I hope this helps resolves your query.
Thanks!
0 Comments
See Also
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!