Unable to run a .NET console exe from MATLAB

2 views (last 30 days)
I was able to run below commands successfully.
system('notepad.exe')
system('C:\Program Files (x86)\Microsoft Office\Office15\winword.exe')
but when i try to run my console application then i get below error.
Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
ans =
0
my program is something like this. my program uses external library(dll) which uses some other libraries internally. when i run the same program from command line in windows, it works fine. but it doesnt work when I run from matlab. If i create a simple hello world, then it works fine in matlab.
system('D:\Work\ConsoleApplication1.exe')
any idea how can i be able to call .net exes from matlab?
  1 Comment
Suresh Veeragoni
Suresh Veeragoni on 20 Nov 2014
I even tried to run the program from a batch file and that also gave same issue. when i run the batch file independently in command line it works fine
system('D:\Work\Convert.bat')
i get below error
D:\Work>cmd /k D:\Work\ConsoleApplication1.exe
Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
my bach file something like this(named as Convert.bat)
cmd /k %~dp0ConsoleApplication1.exe
pause

Sign in to comment.

Accepted Answer

Suresh Veeragoni
Suresh Veeragoni on 20 Nov 2014
ok. here is the answer.
Its working once I change the directory and execute the program directly .net seem doesnt like executing console applications with full path.
cd('path of the folder where the exe is')
system('exe name')

More Answers (1)

Guillaume
Guillaume on 20 Nov 2014
Edited: Guillaume on 20 Nov 2014
Rather than using system you could just use matlab interface to .Net:
asm = NET.addAssembly('D:\Work\ConsoleApplication1.exe');
asm.Program.Main(); %Assuming that's the name of your startup class
No idea, if it will solve your error though.
  2 Comments
Suresh Veeragoni
Suresh Veeragoni on 20 Nov 2014
That didn't work. but i was able to reproduce this issue in windows. When i give full path of the exe in windows, i get the same error
but if i go to that directory and just executes the program then i dont get error. even in windows command line. so, this problem sounds like i need to call the program by going to that directory. do you know how to do that?!
I tried your suggestion. it didnt work :( i get this error. No appropriate method, property, or field Program for class NET.Assembly.
Suresh Veeragoni
Suresh Veeragoni on 20 Nov 2014
thank you for your inputs. the issue was not being in the same directory

Sign in to comment.

Categories

Find more on Search Path 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!