http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 10781|回复: 6

[其他] 【混合编程】C#调用matlab

[复制链接]
发表于 2013-11-5 19:43:36 | 显示全部楼层 |阅读模式
按照网上教程,在C#中调用matlab编译产生的.dll文件,在初始化类时出现异常,请问如何解决??


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-11-5 22:37:17 | 显示全部楼层
出什么异常
 楼主| 发表于 2013-11-6 21:17:26 | 显示全部楼层

“test.demo类型初始值设定项引发异常”。test.demo是我在matlab中封装的类, test.demo output = new test.demo();该语句编译时通过,但在调试时显示出该错误。已经将matlab生成的dll文件放置debug目录下,但仍出现该问题

发表于 2013-11-7 08:24:24 | 显示全部楼层
我估计是你在这个 test.demo里有调用Webconfig文件的数据,而在你调用的这个项目里有没有这个项,所以为出错的,在那个项目里使用这个Dll就要在那个项目中配置,而不是直接配置在Dll所在项目就行了
 楼主| 发表于 2013-11-7 10:45:05 | 显示全部楼层
站长苏飞 发表于 2013-11-7 08:24
我估计是你在这个 test.demo里有调用Webconfig文件的数据,而在你调用的这个项目里有没有这个项,所以为出 ...

站长您好,matlab中的代码很简单,http://wenku.baidu.com/view/a2d173e2524de518964b7d0e.html 就是按照文库文章的步骤逐步做下来,应该不涉及网络部分的。

发表于 2013-11-7 10:49:34 | 显示全部楼层
这个错误报的就是没有取到值的问题呀,
你贴下报错部分的代码,看看有没有访问Config的
 楼主| 发表于 2013-11-7 11:06:07 | 显示全部楼层
站长苏飞 发表于 2013-11-7 10:49
这个错误报的就是没有取到值的问题呀,
你贴下报错部分的代码,看看有没有访问Config的

未处理 System.TypeInitializationException
  Message=“test.demo”的类型初始值设定项引发异常。
  Source=test
  TypeName=test.demo
  StackTrace:
       在 test.demo..ctor()
       在 myapp.Form1.button1_Click(Object sender, EventArgs e) 位置 D:\visualstudio2010\Projects\myapp\myapp\Form1.cs:行号 24
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 myapp.Program.Main() 位置 D:\visualstudio2010\Projects\myapp\myapp\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.TypeInitializationException
       Message=“MathWorks.MATLAB.NET.Utility.MWMCR”的类型初始值设定项引发异常。
       Source=test
       TypeName=MathWorks.MATLAB.NET.Utility.MWMCR
       StackTrace:
            在 test.demo..cctor()
       InnerException: System.TypeInitializationException
            Message=“MathWorks.MATLAB.NET.Arrays.MWArray”的类型初始值设定项引发异常。
            Source=MWArray
            TypeName=MathWorks.MATLAB.NET.Arrays.MWArray
            StackTrace:
                 在 MathWorks.MATLAB.NET.Utility.MWMCR..cctor()
            InnerException: System.BadImageFormatException
                 Message=试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
                 Source=MWArray
                 StackTrace:
                      在 MathWorks.MATLAB.NET.Arrays.MWArray.mclmcrInitialize2(Int32 primaryMode)
                      在 MathWorks.MATLAB.NET.Arrays.MWArray..cctor()
                 InnerException:
///////////////////////////////////////////////////////////////////////
以上就是异常的详细信息。

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-15 14:45

© 2014-2021

快速回复 返回顶部 返回列表