System.IO.FileLoadException when running C# program on a different computer

痞子三分冷 提交于 2019-12-07 16:18:10

问题


I am currently working on a C# WPF project which makes use of the MySQL.Data and System.Data.Sqlite dll as well as a couple of others.

The project is a .Net 4 project which works without problems on my Development Machine. I create an MSI installer package and when I add the executable Visual Studio works out the dependencies and adds the required DLL's with the EXE.

When I run the installer on my development machine everything works fine. However, when I copy the installer to a Blank Virtual machine with .Net Framework 3.5 and .Net Framework 4 installed the installer says that everything has installed successfully, when I look in the program files folder all the DLLs are there as well, but when I try to run the software the software doesn't load and .Net Runtime error is shown in the event viewer.

The error is as follows

Application: MySQLBackup.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileLoadException Stack: at MySQLBackup.App.Application_Startup(System.Object, System.Windows.StartupEventArgs) at System.Windows.Application.OnStartup(System.Windows.StartupEventArgs) at System.Windows.Application.<.ctor>b__1(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) at System.Threading.ExecutionContext.runTryCode(System.Object) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(System.Object) at System.Windows.Application.RunInternal(System.Windows.Window) at System.Windows.Application.Run(System.Windows.Window) at System.Windows.Application.Run() at MySQLBackup.App.Main()

The error message doesn't really help me to figure out what is wrong so in the Application Start up event I added try catch statements but the exception is never caught. I also added try catch around InitialiseComponent() method which is executed on the first dialogue window that should load, but again the catch is never caught so I cannot see what is causing the error.

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


回答1:


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

Perform a remote debug using the visual studio remote debugger.

This tutorial gives an idea of how to use it.

Once you get familiar with the VS Remote Debug, you will always use this powerful tool to test on a potential client environment.

As for your particular problem, you have some code in the Application.Startup event handler that tries to load some file and fails. Post a code in your App.xaml so we can analyze, if you won't be able to find the problem source yourself.




回答2:


Fuslogw could help investigate errors with library binding see Fuslogvw.exe (Assembly Binding Log Viewer)

How you create Sqllite connection? May be this post help DbProviderFactory




回答3:


According to the stack trace the problem is occuring in Application_Startup which was called by OnStartup. Therefore you should check if you've implemented/overridden or wired up to those events in code that might be gerenating those exceptions. Since it is possible for multiple methods to subscribe to the event handler, there's no guarantee the problem is in your code.

You could create some logging checkpoints to help narrow down the location of the error, as well as log values in the context of the error.

You could also use remote debugging to try and narrow down the location of the error.

There are also a couple of Unhandled Exception even handlers that you can google and learn how to implement so that you can perform logging whenever the error occurs, but generally at that point it's far to late to get anymore information other than closing gracefully, so that's probably a alst ditch approach.

You can also use the SysInternals tools like this to determine what files the program is attempting to access, and filter down to failures: http://technet.microsoft.com/en-us/sysinternals/bb896645

You could determine what the last file it was attempting to access was, and even possibly see what the error is at the OS level. I've found this tool to be valuable in dealing with strange file access problems. It takes a while to figure out though.



来源:https://stackoverflow.com/questions/7450634/system-io-fileloadexception-when-running-c-sharp-program-on-a-different-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!