A user of my program has reported an inability to startup the application. I am not yet done troubleshooting, but I’m simply baffled.
Logging still works, so I used logging statements and was able to narrow down the crash to a single line in a user control’s InitializeComponent:
this.HorizontalBox.Image =
((System.Drawing.Image)(resources.GetObject(“HorizontalBox.Image”)));
Here are the relevant clues from his end:
- 64 bit Windows 7
- Correct .NET Framework (4.0 Client Profile)
- No visual elements ever show, and no error dialogs. It is a silent shutdown when starting.
- Logging works, but there were no logged errors.
- He has uninstalled and reinstalled the .NET 4.0 Client Profile framework.
- He doesn’t have any Visual Studio or other development tools mucking with stuff.
I have spent a week or so eliminating theories and I’m becoming confused and desperate. Here are relevant details and things I have found:
- I am targeting x86 explicitly.
- The logging which failed to log any exception is set up to catch and log any unhandled exceptions and thread abort exceptions.
- Whatever is killing the application also prevents the final “shutting down” logging message in the program’s basic entry point.
- I had read that certain icon (.ICO) file formats don’t work in Windows XP. A far fetched theory, since this is Windows 7. This is the one and only case of ICO files in the project, so I was suspicious and switched it to PNG. No difference. I since figure that the image is failing merely because it is the first image loaded from a resource.
- I had read that the Form_Load event may swallow exceptions (and only when debugging). Also, InitializeComponent() is in the constructor, so the theory was shaky. Nonetheless, I wrapped the call to InitializeComponent() in a try/catch, but the catch and its associated logging never get called.
- I have seen posts about resource compilation problems between x86 and x64, but nothing relevant to runtime issues. (See this post)
- I assumed there must be something wrong unique with the program showing issues, so I made a WindowsFormsApplication1 test application with nothing more than a single image embedded in the associated resource file. This also fails to load in the same way. This test application was also targeting x86.
- It works fine on other x86 and x64 machines!
What could possibly be going on his machine? Why is exception handling failing me? This problem is crazy!
Edit: More Details, and I’m still baffled!
- I have since sent the test application (a single form with a single image on it) built as x86, x64, and “Any Cpu”. The x64 and “Any Cpu” applications both work.
Some questions spring to mind. Have you got a similar build machine with which to test – this may help to identify if it is the build/program integration or some possible issue with his build (i.e. a windows problem/virus/etc).
Has he installed to the default folder or did he do a customised install?
Has he tried a full uninstall / reinstall of your app? (I note you said the runtime was refreshed) – possibly to a different folder to make sure.
Can you recreate on a similar build (OS version) with VS installed to do a code walkthrough in the debugger – stack trace and output buffer may help identify – so may disasembly – and can set it to stop at all exceptions?
Unfortunatly unhandled exceptions can not always be caught in C# (especially post 2.0) – so a debugger of WinDBG may be your only option in the end (yuk!).
Can I suggest something though first…Just a thought:
Before the line that fails, as a test, output something like this:
Because I have a feel that the failure is happening when trying to marshal the resource into the Bitmap Type and getting a memory exception (maybe something corrupt with the image stride/pixel format etc or maybe something on the culprit machine is making the image file look like a non image file).