Calling class and methods from C# dll

7 vues (au cours des 30 derniers jours)
Kiruthika
Kiruthika le 15 Mai 2025
Modifié(e) : Ronit le 11 Juin 2025
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;
}
}

Réponses (1)

Ronit
Ronit le 11 Juin 2025
Modifié(e) : Ronit le 11 Juin 2025
Hello @Kiruthika,
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!

Catégories

En savoir plus sur Debugging and Analysis dans Help Center et File Exchange

Produits


Version

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by