集成MATLAB和Visual Basic时出错

时间:2014-01-27 14:09:59

标签: vb.net matlab

程序很简单,只添加两个数字。这是我在.NET程序集中创建和构建的matlab函数

function out = addMe(a,b)
out = a+b;
end

然后我使用网元构建器工具箱生成.NET组件:http://imagizer.imageshack.us/v2/800x600q90/823/f77h.jpg

Imports Add

Public Class Form1
    Dim a As Integer = 5
    Dim b As Integer = 10
    Dim res
    Dim addme As New AddClass

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        res = addme.addMe(a, b)
        TextBox1.Text = res
    End Sub
End Class

但是当我运行程序时,我收到了这个错误:

System.InvalidOperationException was unhandled
  HResult=-2146233079
  Message=An error occurred creating the form. See Exception.InnerException for details.  The error is: Could not load type 'Add.AddClass' from assembly 'Add, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
  Source=Add
  StackTrace:
       at Add.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
       at Add.My.MyProject.MyForms.get_Form1()
       at Add.My.MyApplication.OnCreateMainForm() in c:\users\elvin gentiles\documents\visual studio 2013\Projects\Add\Add\My Project\Application.Designer.vb:line 35
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at Add.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.TypeLoadException
       HResult=-2146233054
       Message=Could not load type 'Add.AddClass' from assembly 'Add, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
       Source=Add
       TypeName=Add.AddClass
       StackTrace:
            at Add.Form1..ctor()
       InnerException: 

1 个答案:

答案 0 :(得分:0)

您需要在.NET应用程序中添加所需的MatLab组件才能运行MatLab功能。

点击此链接,我创建了一些可能会让您对添加Matlab程序集有所了解:

http://www.youtube.com/watch?v=V-HmKmnsK88(第2部分)

http://www.youtube.com/watch?v=gYJ7Q4liNYw(第1部分)

希望这有帮助。