I wrote a small WinForms application in C# with Visual Studio 2010.
It worked quite well in my environment, but I noticed that I need to run the application at the customer site on a Windows Server 2003 SP2 server with the .NET Framework 2.0 installed.
I then built the application with .NET Framework 2.0 as the target framework. Again the application ran perfectly fine on my computer.
At the customer server I noticed a strange behaviour. After starting the application, a black window opens for half a second and closes afterwards. I don’t get an error message.
I discovered that the application doesn’t even enter the main function.
How can this be debugged further, and/or solved?
What you need to do is subscribe to two events: UnhandledException and AssemblyResolve. The first is triggered on … an unhandled exception (of course). The second fires when .NET encounters an assembly reference that it cannot resolve. One or both of these will help you trap your error on the target machine.
You should registered these two event handlers at the very beginning on your code, as shown.
Hope this helps!