在C#类库中使用MATLAB MWArray.dll [英] Using MATLAB MWArray.dll in C# Class Library

查看:278
本文介绍了在C#类库中使用MATLAB MWArray.dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 C#类库中的MATLAB和Matlab .net Complier内置的.​​dll,但是例如,每次初始化MWArray.dll中的对象时,程序都会引发异常. :

I'm trying to use .dll, built in MATLAB with Matlab .net Complier, in C# Class Library, but program throws an exception every time object from MWArray.dll is initialized, for example:

MWNumericArray m = new MWNumericArra(10,10);

例外:

System.TypeInitializationException was caught
  HResult=-2146233036
  Message=The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWNumericArray' threw an exception.
  Source=MWArray
  TypeName=MathWorks.MATLAB.NET.Arrays.MWNumericArray
  StackTrace:
       at MathWorks.MATLAB.NET.Arrays.MWNumericArray.op_Implicit(Double[] values)
       at VolCalc.Vol.CalculateVolatility(Double[] data)
  InnerException: System.TypeInitializationException
       HResult=-2146233036
       Message=The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWIndexArray' threw an exception.
       Source=MWArray
       TypeName=MathWorks.MATLAB.NET.Arrays.MWIndexArray
       StackTrace:
            at MathWorks.MATLAB.NET.Arrays.MWIndexArray..ctor()
            at MathWorks.MATLAB.NET.Arrays.MWNumericArray..ctor(Double scalar)
            at MathWorks.MATLAB.NET.Arrays.MWNumericArray.get__Inf()
            at MathWorks.MATLAB.NET.Arrays.MWNumericArray..cctor()
       InnerException: System.Security.SecurityException
            HResult=-2146233078
            Message=Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
            Source=MWArray
            StackTrace:
                 at MathWorks.MATLAB.NET.Utility.MWSafeHandle..ctor()
                 at MathWorks.MATLAB.NET.Arrays.MWArray..ctor()
                 at MathWorks.MATLAB.NET.Arrays.MWIndexArray..ctor()
                 at MathWorks.MATLAB.NET.Arrays.MWNumericArray..ctor(MWArrayComponent arrayComponent, Int32 rows, Int32 columns)
                 at MathWorks.MATLAB.NET.Arrays.MWIndexArray..cctor()
            InnerException: 

我试图在Console App中执行此操作,并且工作正常,但是我需要使用在Matlab中内置的.dll的.dll.

I tried to do this in Console App, and works fine, but I need .dll that uses .dll built in matlab.

有什么想法吗?

推荐答案

帮助我的是,确保C#应用程序和matlab模块处于相同的架构下-意味着32位或64位.

What helped me was to make sure the C# application and the matlab modules are under the same architecture - Meaning 32 or 64 bit.

如果您的Matlab是64位-尝试将C#项目更改为64位

If your Matlab is 64 bits - Try changing the C# project to 64 bit

查看此帖子: 创建共享库(.NET Assembly)在Matlab中并在C#中使用它

这篇关于在C#类库中使用MATLAB MWArray.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆