在另一台计算机上运行C#程序时出现System.IO.FileLoadException

我目前正在开发一个C#WPF项目,该项目使用MySQL.Data和System.Data.Sqlite dll以及其他几个。

该项目是一个.Net 4项目,在我的开发机器上没有问题。 我创建了一个MSI安装程序包,当我添加可执行文件Visual Studio时,计算出依赖项,并在EXE中添加所需的DLL。

当我在我的开发机器上运行安装程序时,一切正常。 但是,当我将安装程序复制到安装了.Net Framework 3.5和.Net Framework 4的空白虚拟机时,安装程​​序说已经成功安装了所有内容,当我查看程序文件文件夹时,所有的DLL都在那里,但是当我尝试运行软件未加载的软件,并在事件查看器中显示.Net Runtime错误。

错误如下

应用程序:MySQLBackup.exe Framework版本:v4.0.30319描述:由于未处理的exception,进程终止。 exception信息:System.IO.FileLoadException Stack:位于System.Windows.Application的System.Windows.Application.OnStartup(System.Windows.StartupEventArgs)的MySQLBackup.App.Application_Startup(System.Object,System.Windows.StartupEventArgs)。位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen的System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)中的.ctor> b__1(System.Object)(System.Object,System.Delegate,System位于System.Whows.Threading.Threading.DepatcherOseration上的System.Windows.Threading.DispatcherOperation.InvokeImpl()处的System.Threading.ExecutionContext.runTryCode(System.Object)处的System.Windows.Threading.DispatcherOperation.InvokeImpl()处于.Object,Int32,System.Delegate。 System.Threading.ExecutionContext上的System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)中的System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode,CleanupCode,System.Object) System.Windows上的System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)中的.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean) .Threading.DispatcherOperation.Invoke()在MS.Win32.HwndWrapper.WndProc的System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr,IntPtr,Boolean ByRef)的System.Windows.Threading.Dispatcher.ProcessQueue()处。 (IntPtr,Int32,IntPtr,IntPtr,Boolean ByRef)位于MS.Internal的System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)中的MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) System.Windows.Threading.Dispatcher.InvokeImpl中的.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)(System.Windows.Threading.DispatcherPriority,System.TimeSpan,System。委托,System.Object,Int32)在MS.Win32.HwndSubclass.SubclassWndProc System.Windows上System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)的MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)上的(IntPtr,Int32,IntPtr,IntPtr) System.Windows.Application.RunInternal(系统中的System.Windows.Application.RunDispatcher(System.Object)上的System.Windows.Threading.Dispatcher.Run()中的.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) .Windows.Window)位于System.Windows.Application.Run(System.Windows.Window)的System.Windows.Application.Run(),位于MySQLBackup.App.Main()

错误消息并没有真正帮助我找出错误所以在Application Start up事件中我添加了try catch语句但是exception永远不会被捕获。 我还在InitialiseComponent()方法中添加了try catch,它在应该加载的第一个对话窗口上执行,但是再次捕获的东西永远不会被捕获,所以我看不出导致错误的原因。

我怎样才能弄清楚这个问题是什么并修复它?

 How can I figure out what this problem is and fix it. 

使用visual studio远程调试器执行远程调试 。

本教程介绍了如何使用它。

熟悉VS远程调试后,您将始终使用此强大的工具来测试潜在的客户端环境。

至于您的特定问题,您在Application.Startup事件处理程序中有一些代码尝试加载某个文件并失败。 在App.xaml中发布代码,以便我们可以分析,如果您自己无法找到问题来源。

Fuslogw可以帮助调查库绑定的错误,请参阅Fuslogvw.exe(程序集绑定日志查看器)

你如何创建Sqllite连接? 可能是这个post帮助DbProviderFactory

根据堆栈跟踪,问题出现在OnStartup调用的Application_Startup中。 因此,您应检查是否已在代码中实现/覆盖或连接到那些可能导致这些exception的事件。 由于多个方法可以订阅事件处理程序,因此无法保证代码中存在问题。

您可以创建一些日志记录检查点,以帮助缩小错误的位置,以及在错误的上下文中记录日志值。

您还可以使用远程调试来尝试缩小错误的位置。

还有一些Unhandled Exception甚至处理程序,你可以谷歌并学习如何实现,以便你可以在错误发生时执行日志记录,但通常在那时,除了优雅地关闭之外,获取更多信息已经很晚了,所以这是可能是一个沟渠的方法。

您还可以使用这样的SysInternals工具来确定程序尝试访问的文件,并过滤到故障: http : //technet.microsoft.com/en-us/sysinternals/bb896645

您可以确定它尝试访问的最后一个文件是什么,甚至可能看到操作系统级别的错误。 我发现这个工具在处理奇怪的文件访问问题时很有价值。 虽然需要一段时间来弄明白。