MATLAB Runtime 2024b TypeInitia​lizationEx​ception in COM-registered Windows Forms Control Library

9 visualizaciones (últimos 30 días)
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:
  1. Create a Windows Forms Control Library.
  2. Set up as described in MATLAB documentation.
  3. Use the MATLAB Runtime library (e.g., initialize a MWArray).
  4. Build and test it within a Windows Forms App or WPF App — it works fine.
  5. Register the control as a COM component and use it in an external application (e.g., Excel).
  6. 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.

Respuestas (0)

Categorías

Más información sobre Deploy to .NET Applications Using MWArray API en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by