.NET Assembly dll in C# with error "Not enough input arguments"

4 Ansichten (letzte 30 Tage)
I am trying to get a simple .NET assembly working before I tackle the real thing. I am either getting "Not enough input arguments" and other times, "Not enough output arguments".
I have made sure that I have the matching MWArray.dll on my c# development computer.
MWArray and my Matlab created dll (TestAddCompiled.dll) have been referenced
I have left the commented out attempts I have made.
In the Matlab console: nargin is 3, nargout is 1
MATLAB R2019a, C# Visual Studio 2015
Matlab code:
function [c] = TestAdd(a,b,iAdd)
% Helper function used in testing type safe API.
%if ~isnumeric(a) || ~isnumeric(b)
% error('Input must be numeric. Input was %s and %s.', class(a), class(b));
%end
switch iAdd
case 1
c = a + b;
case 0
c = Multiply(a,b);
otherwise
c = Multiply(a,b);
end
% if iAdd==1
% c = a + b;
% else
% c = Multiply(a,b);
% end
end
function d = Multiply(a,b)
d = a * b;
end
Matlab library compiler:
C# Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using TestAddCompiled;
namespace TestAddC
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//initialize instance of Matlab class
clsAdd clsMyAdd = new clsAdd();
//Dead Code
/*MWNumericArray dFirst = new MWNumericArray(new Int64());
MWNumericArray dSecond = new MWNumericArray(new Int64());
MWNumericArray dThird = new MWNumericArray(new Int64());
dFirst = Convert.ToInt64(5);
dSecond = Convert.ToInt64(5);
dThird = Convert.ToInt64(5);*/
//End Dead Code
//Create array of inputs
Int64[] dArrInput = { 5,6,1 }; //also tried Int32 and double
MWArray[] dArrOutput = null;
//dArrOutput = 0;
// MWNumericArray mlArrInput = new MWNumericArray(dArrInput);
//Create and convert inputs to MWNumericArray
MWNumericArray inputs = null;
inputs = new MWNumericArray(1, 3, dArrInput);
MessageBox.Show("Inputs: " + inputs.ToString());
//double dOutput = 0;
//dArrOutput = clsMyAdd.TestAdd(1, dFirst, dSecond, dThird);
//dArrOutput = clsMyAdd.TestAdd(1, mlArrInput);
//dOutput = clsMyAdd.TestAdd(5,6,1);
//dArrOutput[0] = clsMyAdd.TestAdd(5, 6, 1);
//dArrOutput = clsMyAdd.TestAdd(1, 3, mlArrInput); //#output, #input, array
//dArrOutput = clsMyAdd.TestAdd(1, mlArrInput); //0 based #output, #input, array
dArrOutput = clsMyAdd.TestAdd(1, inputs); //1 output, inputs
}
}
}
Error:
System.Exception was unhandled
HResult=-2146233088
Message=
... MWMCR::EvaluateFunction error ...
Not enough input arguments.
Error in => TestAdd.m at line 8.
... Matlab M-code Stack Trace ...
at
file C:\Users\cbonneau\AppData\Local\Temp\cbonneau\mcrCache9.6\TestAd3\TestAddCompi\TestAdd.m, name TestAdd, line 8.
Source=MWArray
StackTrace:
at MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(String functionName, Int32 numArgsOut, Int32 numArgsIn, MWArray[] argsIn)
at MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(Int32 numArgsOut, String functionName, MWArray[] argsIn)
at TestAddC.Form1.button1_Click(Object sender, EventArgs e) in C:\TestFolder\TestAddC\TestAddC\Form1.cs:line 61
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at TestAddC.Program.Main() in C:\TestFolder\TestAddC\TestAddC\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Akzeptierte Antwort

Kojiro Saito
Kojiro Saito am 10 Jul. 2019
Since your TestAdd function requires three input arguments and your inputs in C# is one array, you need to put each input separately.
Please replace the last code (dArrOutput=...) in C# to the following.
dArrOutput = clsMyAdd.TestAdd(1, inputs[1], inputs[2], inputs[3]); //1 output, inputs
MessageBox.Show("Outputs: " + dArrOutput[0].ToString());

Weitere Antworten (0)

Kategorien

Mehr zu Deploy to .NET Applications Using MWArray API finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by