Why does Matlab crash when I try to access .NET 6.0 (core)?
조회 수: 50 (최근 30일)
이전 댓글 표시
Note: Workaround is to remove .NET 9.0 from PC to resolve conflicts with 6.0.
This might be a .NET issue as a whole, but I only see it using Matlab, so I am posting here to help others out facing the same issues.
I have a .dll from one of the groups I work with for communicating to our devices. The .dll was built in .NET 6.0 (core) (x64). I have been able to use it in the past in Matlab, but have now run into issues since installing Visual Studio 2022. It was discovered that Matlab would reference the most recent installation of .NET (9.0 in my case) which was installed by VS 2022. When I set "core" as the environment in Matlab (dotnetenv("core")), I would then make the .NET assembly visible to Matlab using NET.addAssembly("insert path here"). When Matlab got to this step, it would buffer for about 10 seconds then crash immediately with no crash report. Getting help from my local IT, we pin pointed it to the .NET 9.0 install causing the problem.
To get around this, you can either uninstall 9.0 or set up an environment variable in your system properties called "DOTNET_ROOT" that can force a path to be referenced.
So I would like to ask if anyone else has faced this issue in Matlab? Is it an unexpected error that needs an error handle? I am naive to .net, and really only know the particular dll I interact with to do my methods, etc.
댓글 수: 0
채택된 답변
aditi bagora
2024년 11월 22일
I have faced the same issue. I found that this issue is specific to .NET 9.0 and does not originate from MATLAB.
After installing Visual Studio 2022, your system updates to the latest version of .NET, which is .NET 9.0 and MATLAB by default, uses the latest version of .NET installed on your system(refer the documentation below), this can lead to a crash. Therefore, uninstalling .NET 9.0 or setting "DOTNET_ROOT" path is solving the issue.
I hope this helps!
추가 답변 (2개)
埃博拉酱
2024년 11월 22일
편집: 埃博拉酱
2024년 12월 18일
20241218
An easier workaround, from tech support:
feature("USE_DOTNETCLI2_WINDOWS", 1)
댓글 수: 3
Sam Cook
2025년 5월 14일
Hey there! I submitted that issue with Microsoft. The feature switch you referenced tells MATLAB to use a new approach to load and interface with .NET Core on Windows. This approach is not ready for production environments, but is a quick way to work around the issue if you must use .NET 9 with MATLAB up to R2024b.
Further, .NET 9.0.5 fixed the original issue but introduced another, so .NET 9 is unfortunately still not usable with MATLAB. I also just checked the .NET 10 RC and found the same issue, so I'll be looking into that.
As the poster mentioned, you can still set DOTNET_ROOT, uninstall .NET 9, or edit matlab\bin\win64\dotnetcli_netcore.runtimeconfig.json to work around the issue.
Richard Scott
2024년 12월 10일
I found just pasting the following code into MATLAB script editor is enough to crash MATLAB without even trying to run the script.
asm = NET.addAssembly('System.Windows.Forms');
import System.Windows.Forms.*
MessageBox.Show('Simple Message Box');
also running the following line would be enough to crash MATLAB.
NET.isNETSupported
Windows Event Log contains the unhandled exception data. In additiona to any fix that Microsoft may implement, MATLAB may want to try catch the unhandled exception for a more gracefull user experience.
My workaround was to edit the config file as described in the MATLAB help section "System Requirements for Using MATLAB Interface to .NET". Specifically I changed
"rollForward": "LatestMajor"
to
"tfm": "net6.0",
With the complete file as follows:
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.WindowsDesktop.App",
"version": "6.0.0"
}
}
}
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!