.NET changes between 2017b and 2018a

9 visualizzazioni (ultimi 30 giorni)
KN
KN il 24 Apr 2018
Modificato: thrunken il 18 Giu 2018
I have some code where I use a .dll created with vb.net inside VS2013 to use with matlab:
net = NET.addAssembly('SOME_PROJECT.dll');
AssemblyType = net.AssemblyHandle.GetType('SOME_PROJECT.ComClass');
try
result = System.Activator.CreateInstance(AssemblyType);
catch e
e.message;
if(isa(e, 'NET.NetException'))
eObj = e.ExceptionObject
end
end
This works fine in matlab 2017b and will yield 'result' but in 2018a I get a SEHException
e =
NetException with properties:
ExceptionObject: [1×1 System.Runtime.InteropServices.SEHException]
identifier: 'MATLAB:NET:CLRException:AddSuperClasses'
message: 'Message: External component has thrown an exception.↵Source: dotnetcli↵HelpLink: '
cause: {}
stack: [0×1 struct]
What changes between 2017b and 2018a could cause this? What can I do to fix this?
  2 Commenti
zapaiz
zapaiz il 1 Giu 2018
Modificato: zapaiz il 4 Giu 2018
I have the same problem passing from 2017b (where there script was running correctly) to 2018a:
NET.addAssembly(plc-full-path);
plc.objCom=PoohPlcLink.PoohFinsETN;
The second line throws an error:
NetException with properties:
ExceptionObject: [1×1 System.Runtime.InteropServices.SEHException]
identifier: 'MATLAB:NET:CLRException:AddSuperClasses'
message: 'Message: Eccezione lanciata da un componente esterno.↵Source: dotnetcli↵HelpLink: '
cause: {}
stack: [3×1 struct]
The NetExeption is contained in the attached workspace.
thrunken
thrunken il 1 Giu 2018
Modificato: thrunken il 1 Giu 2018
I found this post while searching for a solution to my own similar problem. Below is some C# code and a MATLAB script I wrote. I've been able to reproduce the exception I've been getting when using another dll. The script works in 2017b, but not 2018a.
C# code:
namespace SimpleDLL
{
public class OuterClass
{
public class NestedClass
{
public NestedClass() { }
}
public class InheritedNestedClass : NestedClass
{
public InheritedNestedClass() { }
}
// Returns without error in MATLAB 2018a
public NestedClass GetNestedClass()
{
return new NestedClass();
}
// Throws an error in MATLAB 2018a
public InheritedNestedClass GetInheritedNestedClass()
{
return new InheritedNestedClass();
}
}
}
MATLAB script:
dll = NET.addAssembly('SimpleDLL.dll');
outerClass = SimpleDLL.OuterClass();
% Does not throw exception
nested = outerClass.GetNestedClass();
% Throws exception
inheritedNested = outerClass.GetInheritedNestedClass();
The exception is:
Error using SimpleDll (line 6)
Message: External component has thrown an exception.
Source: dotnetcli
HelpLink:
I can return a nested class (class within a class), but I cannot return a class that inherits from the same nested class. I am using .NET Framework 4.6.1 if that matters. There seems to be no difference in what MathWorks has reported as limitations in .NET support between 2018a and 2017b, so I'm confused as to what the problem could be.

Accedi per commentare.

Risposta accettata

thrunken
thrunken il 4 Giu 2018
Modificato: thrunken il 18 Giu 2018
I posted a comment here and discovered that my problem is caused by a known bug in MATLAB 2018a. https://www.mathworks.com/support/bugreports/1759533
Could this be your problem?
Edit: They fixed the bug, install 2018a Update 3.
  4 Commenti
zapaiz
zapaiz il 8 Giu 2018
Good to know. Sadly I'm using a third party dll, I had to switch back to 2017b.
thrunken
thrunken il 18 Giu 2018
It's fixed now, 2018a should work fine.

Accedi per commentare.

Più risposte (1)

Antony Pohl
Antony Pohl il 8 Giu 2018
I have the same problem, but it's a deal breaker for me as I am heavily invested in Win Forms GUI and a custom VB .dll that I call frequently.
At the most basic level you can't even open a simple form. I can't believe that made it passed the testers into a published product Very bad on Matlab.
Example:
------
asm = NET.addAssembly('System.Windows.Forms');
import System.Windows.Forms.*
a = Form; <---- this produces the above mentioned dotnetcli error.
--------

Tag

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by