qq_17621737 2021-09-23 16:45 采纳率: 0%
浏览 148

C#调用matlab出现“MWNumericArray的类型初始值设定项引发异常”错误,求解!!。

 MWArray plotValue =  (MWNumericArray)new double []{1,2,3,4,5,6 };

System.TypeInitializationException
HResult=0x80131534
Message=“MathWorks.MATLAB.NET.Arrays.MWNumericArray”的类型初始值设定项引发异常。
Source=MWArray
StackTrace:
在 MathWorks.MATLAB.NET.Arrays.MWNumericArray..ctor(Array array)
在 ECOCwpf.Service.Nihe(Boolean isOneNihe) 在 D:\项目\部门项目\OCEC\Online_OCEC - 日常测试版本\Online_OCEC_liang20210712\Online_OCEC_liang\Online_OCEC\EC_OCAnalyzer\ECOCwpf\Service.xaml.cs 中: 第 705 行
在 ECOCwpf.Service.buttonNiheTwo_Click(Object sender, RoutedEventArgs e) 在 D:\项目\部门项目\OCEC\Online_OCEC - 日常测试版本\Online_OCEC_liang20210712\Online_OCEC_liang\Online_OCEC\EC_OCAnalyzer\ECOCwpf\Service.xaml.cs 中: 第 741 行
在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
在 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
在 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
在 System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
在 System.Windows.Controls.Primitives.ButtonBase.OnClick()
在 System.Windows.Controls.Button.OnClick()
在 System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
在 System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
在 System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
在 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
在 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
在 System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
在 System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
在 System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
在 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
在 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
在 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
在 System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
在 System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
在 System.Windows.Input.InputManager.ProcessStagingArea()
在 System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
在 System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
在 System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
在 System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

内部异常 1:
TypeInitializationException: “MathWorks.MATLAB.NET.Arrays.MWArray”的类型初始值设定项引发异常。

内部异常 2:
TypeInitializationException: “MathWorks.MATLAB.NET.Utility.MWMCR”的类型初始值设定项引发异常。

内部异常 3:
BadImageFormatException: 试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)

  • 写回答

1条回答 默认 最新

  • 小甲鱼同学 2023-02-12 13:08
    关注

    这种错误通常是因为Matlab引擎和.Net Framework的版本不兼容造成的。为了解决这个问题,可以尝试以下步骤:

    确保你正在使用的Matlab引擎版本与.Net Framework版本兼容。可以查看Matlab引擎文档或联系Matlab支持团队获取更多信息。

    确保正确安装了Matlab引擎,并且已将其添加到系统环境变量中。

    确保在C#项目中正确引用了Matlab引擎组件,并且使用了正确的命名空间。

    尝试在调用Matlab函数之前创建MWNumericArray对象。例如,可以使用以下代码创建一个包含双精度浮点数的MWNumericArray对象:

    MWNumericArray arr = new MWNumericArray(3, 3, new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });

    如果上述步骤都没有解决问题,可以考虑重新安装Matlab引擎或者联系Matlab支持团队获取帮助。

    评论

报告相同问题?

问题事件

  • 创建了问题 9月23日

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题