簡體   English   中英

dll Matlab實例在C#中運行發行版時引發異常

[英]dll Matlab instance throw an exception while running release in c#

我的c#程序使用Matlab dll,只要我在“調試”模式下運行它,它就可以找到。 但是當我嘗試在發布模式下運行它時,在創建實例時立即崩潰。

它引發TypeInitializationException。

謝謝你的幫助

堆棧跟蹤:

"at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
 at System.Environment.get_StackTrace()
 at Turbo_Neuron.ANNController..ctor() 
    in C:\\Users\\Eli\\Desktop\\....\\MyProject\\Program.cs:line 17
        at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
        at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
        at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
        at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
        at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
        at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
        at System.Activator.CreateInstance(ActivationContext activationContext)
        at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
        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()"

它說:

The type initializer for 'MatlabANNComp.MatlabANN' threw an exception.

StachTrace 2:

   at MatlabANNComp.MatlabANN..ctor()
   at Turbo_Neuron.ANNController..ctor() in C:\Users\Eli\Desktop\Work_ANN\ANN\working\Current\Turbo_Neuron_Pro_Filxed_10.09.13_N\Turbo_Neuron\Matlab_Layer\ANNController.cs:line 49
   at Turbo_Neuron.TNController..ctor(pnl_main form) in C:\Users\Eli\Desktop\Work_ANN\ANN\working\Current\Turbo_Neuron_Pro_Filxed_10.09.13_N\Turbo_Neuron\Logic_Layer\TNController.cs:line 49
   at Turbo_Neuron.pnl_main..ctor() in C:\Users\Eli\Desktop\Work_ANN\ANN\working\Current\Turbo_Neuron_Pro_Filxed_10.09.13_N\Turbo_Neuron\View_Layer\Turbo_Form.cs:line 29
   at Turbo_Neuron.Program.Main() in C:\Users\Eli\Desktop\Work_ANN\ANN\working\Current\Turbo_Neuron_Pro_Filxed_10.09.13_N\Turbo_Neuron\Program.cs:line 17
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
   at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
   at System.Activator.CreateInstance(ActivationContext activationContext)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
   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()

異常消息:

Exception.Message = 
"The type initializer for 'MatlabANNComp.MatlabANN' threw an exception."

InnerException.Message =
{"Could not load file or assembly 'MWArray, Version=2.10.1.0, 
Culture=neutral, PublicKeyToken=e1d84a0da19db86f' 
or one of its dependencies. An attempt was made 
to load a program with an incorrect format."}

InnerException.InnerException = null

An attempt was made to load a program with an incorrect format

這是關鍵,這意味着您正在混合平台。 32位進程無法加載64位dll,反之亦然。 如果某個進程仍然嘗試這樣做,則會拋出上述異常。 您說您只是從Debug-> Release進行了更改,因此可能也與平台更改有關。 在配置管理器中比較所有項目的設置。 它們都應該是x86或x64( 不是 AnyCPU)。 哪一個取決於您的matlab dll平台(在構建時設置)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM