Search code examples
c#wpffileloadexception

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


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?


Solution

  • 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.