Crash when exception is thrown from .NET 9.0.4
Afficher commentaires plus anciens
MATLAB crashes when an exception is thrown from .NET code and .NET 9 is installed. Here is a reproducer:
public class MatlabTest
{
public void ThrowException()
{
throw new InvalidOperationException("This is a test exception");
}
}
And in MATLAB:
dotnetenv("core");
NET.addAssembly(fullfile(pwd, '.\MatlabTest.dll'));
test = MatlabTest.MatlabTest();
test.ThrowException();
The crash seems similar to Why does Matlab crash when I try to access .NET 6.0 (core)? Indeed the error occurs only when .NET 9 is installed on the machine. It seems like that issue was resolved in .NET 9.0.4 so we upgraded our .NET 9 runtime to 9.0.4, but the issue still exists.

This is what it looks like without .NET 9 installed on the machine (MATLAB always uses the latest .NET runtime):

Following is some of the crash information reported by MATLAB:
Assertion in void __clrcall dotnetcli::HandleBackgroundException(class System::Object ^,class System::UnhandledExceptionEventArgs ^) at B:\matlab\external\interfaces\dotnet\dotnetcli\src\NetPackage.cpp line 81:
Managed .NET code threw an exception. Consider using System.Threading.Tasks.Task APIs. These ensure managed exceptions return to the main thread where they can be handled in MATLAB code.
The following .NET exception caused MATLAB to crash:
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at dotnetcli.throwMException(SByte*, Char*, mxArray_tag*)
at dotnetcli.rethrowTargetInvocationExceptionID(TargetInvocationException e, BaseMsgID* msgID)
a
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Get Started with Microsoft .NET dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!