dll Matlab实例在c#中运行release时抛出异常

时间:2013-09-10 07:01:04

标签: c# matlab matlab-deployment matlab-compiler release-mode

我的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()"

它是sais:

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

1 个答案:

答案 0 :(得分:0)

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

这是关键,这意味着你正在混合平台somwhow。 32位进程无法加载64位dll,反之亦然。如果进程尝试这样做,它会抛出上述异常。 你说你只是从Debug-> Release中改变了,所以它可能与平台有关的东西也发生了变化。比较Configuration Manager中所有项目的设置。它们都应该是x86或x64(不是 AnyCPU)。哪一个取决于您的matlab dll平台(在构建时设置)。