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

3

4

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?

Ramer answered 16/9, 2011 at 21:37 Comment(0)
M
4
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.

Molding answered 16/9, 2011 at 21:47 Comment(3)
Thanks for your help. I have used remote debug and fuslogvw as mentioned by @radik and have an even stranger problem. Its saying System.Data.Sqlite.dll couldn't be found at ...bin/myapp/system.data.sqlite.dll even though the file is there. The weird thing as well this error is also being shown in fuslogvw on the development machine even though the program loads up fine without any exceptions being thrownRamer
Hi found out the problem. It was with the MSI that I had created to install the program. It didn't have the myapp.exe.config file. Once I included this in the MSI it worked great. Thanks to you and @Radik as both your answers helped, wish I could put both of them as an answer. Thanks againRamer
Glad to hear that you got it all figured out :)Molding
M
3

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

Massotherapy answered 16/9, 2011 at 21:50 Comment(1)
This is probably a better first step then trying to get remote debugging working. However it doesn't work without VS installed unless you copy the right files see using FUSLOGVW.EXE on a machine with no Visual Studio installedRedware
M
1

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.

Misplay answered 16/9, 2011 at 21:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.