- R2023b: You must edit the matlabroot\bin\win64\dotnetcli_netcore.runtimeconfig.json file to specify the .NET version in R2023b
- If there is a unique directory containing the .NET version you want, you can set DOTNET_ROOT env var before loading .NET, and MATLAB will search for the highest version in that directory instead.
- Starting in R2025a you can use the Version= and Frameworks= name-value-pairs to select a specific .NET version. System Requirements for Using MATLAB Interface to .NET
Crash when exception is thrown from .NET 9.0.4
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Helen Zhu
am 14 Mai 2025
Verschoben: Walter Roberson
am 15 Mai 2025
The crash can occur with R2023b, R2024a, R2024b. The issue is not present with .NET 8.
By default, MATLAB always uses the latest .NET runtime.
If you have .NET 9.0.4 and 9.0.5 or the .NET 10 release candidate installed on your machine, you can change the .NET runtime that MATLAB uses:
2 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!