MATLAB Runtime 2024b TypeInitializationException in COM-registered Windows Forms Control Library
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I’m facing a blocking issue with MATLAB Runtime in a COM-registered Windows Forms Control Library inside an external application.
The issue arises when I instantiate a MWArray (or anything from the MATLAB Runtime), throwing a TypeInitializationException.
Exception:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWNumericArray' threw an exception.
Source=MWArray
StackTrace:
at MathWorks.MATLAB.NET.Arrays.MWNumericArray..ctor(Double scalar)
at TestWindowsFormsControlLibrary.UserControl1..ctor() in ...\SandboxSolution\TestWindowsFormsControlLibrary\UserControl1.cs:line 32
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception.
Inner Exception 2:
TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception.
Inner Exception 3:
Exception: Trouble initializing libraries required by .NET Assembly.
In other words:
- The issue occurs only when the control library is COM-registered and loaded in an external application (e.g., Excel).
- Without the COM registration, the same control works perfectly in a standalone Windows Forms App or WPF application.
Error Trigger Code
The exception occurs when initializing MWArray like so:
MWArray test = new MWNumericArray(0);
- If I remove this line, the COM application runs fine (no interaction with MATLAB Runtime).
- If I run the same control in a standard Windows Forms App or WPF App, it loads the MATLAB Runtime without issues.
Steps to reproduce:
- Create a Windows Forms Control Library.
- Set up as described in MATLAB documentation.
- Use the MATLAB Runtime library (e.g., initialize a MWArray).
- Build and test it within a Windows Forms App or WPF App — it works fine.
- Register the control as a COM component and use it in an external application (e.g., Excel).
- The TypeInitializationException is thrown.
Environment
- MATLAB Runtime version: 2024b 64-bit
- .NET Framework: 4.8.1 64-bit
- COM architecture: Only 64-bit (AnyCPU is removed)
Expected result:
I expect the MATLAB Library works in the COM-registered control as the Windows Forms Application.
Additional notes: I have only one MATLAB Runtime installed. I have it added in the PATH and it is the only entry.
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Deploy to .NET Applications Using MWArray API in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!