我的 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