【问题标题】:System.IO.FileLoadException when running C# program on a different computer在另一台计算机上运行 C# 程序时出现 System.IO.FileLoadException
【发布时间】:2011-11-19 00:30:41
【问题描述】:

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

该项目是一个 .Net 4 项目,可以在我的开发机器上正常运行。我创建了一个 MSI 安装程序包,当我添加可执行文件时,Visual Studio 会计算出依赖关系并使用 EXE 添加所需的 DLL。

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

报错如下

应用程序:MySQLBackup.exe 框架版本:v4.0.30319 说明:进程因未处理的异常而终止。 异常信息:System.IO.FileLoadException 堆栈:在 MySQLBackup.App.Application_Startup(System.Object, System.Windows.StartupEventArgs)在 System.Windows.Application.OnStartup(System.Windows.StartupEventArgs) 在 System.Windows.Application.<.ctor>b__1(System.Object) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate、System.Object、Int32、System.Delegate)在 System.Windows.Threading.DispatcherOperation.InvokeImpl() 在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) 在 System.Threading.ExecutionContext.runTryCode(System.Object) 在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode,System.Object)在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,布尔值)在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)在 System.Windows.Threading.DispatcherOperation.Invoke() 在 System.Windows.Threading.Dispatcher.ProcessQueue() 在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr, IntPtr, Boolean ByRef) 在 MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate、System.Object、Int32、System.Delegate)在 System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) 在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr) 在 MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)在 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 在 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 在 System.Windows.Threading.Dispatcher.Run() 在 System.Windows.Application.RunDispatcher(System.Object) 在 System.Windows.Application.RunInternal(System.Windows.Window) 在 System.Windows.Application.Run(System.Windows.Window) 在 MySQLBackup.App.Main() 处的 System.Windows.Application.Run()

错误消息并不能真正帮助我找出问题所在,因此在应用程序启动事件中我添加了 try catch 语句,但从未捕获到异常。我还在InitialiseComponent() 方法周围添加了try catch,该方法在应该加载的第一个对话窗口上执行,但再次捕获从未捕获,因此我看不到导致错误的原因。

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

【问题讨论】:

    标签: c# wpf fileloadexception


    【解决方案1】:
    How can I figure out what this problem is and fix it.
    

    使用visual studio remote debugger 执行远程调试。

    This tutorial 提供了如何使用它的想法。

    一旦您熟悉了 VS 远程调试,您将始终使用这个强大的工具在潜在的客户端环境中进行测试。

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

    【讨论】:

    • 感谢您的帮助。我使用了@radik 提到的远程调试和fuslogvw,并且遇到了一个更奇怪的问题。它说 System.Data.Sqlite.dll 无法在 ...bin/myapp/system.data.sqlite.dll 找到,即使文件在那里。奇怪的是,这个错误也显示在开发机器上的 fuslogvw 中,即使程序加载正常而没有抛出任何异常
    • 您好,发现了问题。这是我为安装程序而创建的 MSI。它没有 myapp.exe.config 文件。一旦我将它包含在 MSI 中,它就工作得很好。感谢您和@Radik,因为您的回答都有帮助,希望我能把它们都作为答案。再次感谢
    • 很高兴听到你搞清楚了 :)
    【解决方案2】:

    Fuslogw 可以帮助调查库绑定错误 见Fuslogvw.exe (Assembly Binding Log Viewer)

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

    【讨论】:

    【解决方案3】:

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

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

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

    还有几个 Unhandled Exception 甚至处理程序,您可以通过 Google 搜索并学习如何实现,以便在发生错误时执行日志记录,但通常到那时,除了正常关闭之外,获取更多信息为时已晚,所以这可能是一种 alst ditch 方法。

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

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

    【讨论】:

      猜你喜欢
      • 2014-01-21
      • 1970-01-01
      • 2011-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      相关资源
      最近更新 更多