views:

45

answers:

1

Hi,

The following problem has me stumped: I have a WinForms application which used to work just fine. On Windows7 however, my MainForm's "Load"-event handler is never invoked. I tried Googleing a bit and found suggestions for checking if the Event was correctly connected to the handler (it was), and secondly to try overriding the OnLoad method. The OnLoad override was called once (i think, have been debugging substantially) and then no further. Why is the OnLoad override not called? And what could i try in order to fix this?

Best regards!

+2  A: 

I think I solved it!

This turned out to have nothing to do with the OnLoad-event in particular. Instead it was caused by code inside the OnLoad event-handler, which uses a 32-bit DLL from a 64-bit context. I found a solution for this on bytes.com/topic/c-sharp/answers/...

The confusing bit was, that the 32-bit/64-bit problem caused an exception immediately when entering the event-handler, so a breakpoint immediately inside the event-handler was never hit. I did'nt get an pop-up with the exception either, because the application has a 'CurrentDomain_UnhandledException'-handler... but thats a different story.

S.C. Madsen
Ok, that explains it. To catch such events in the future, you can attach an event handler to the Application.ThreadException (http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx) event in your static Main() method, before you create any form. And putting a breakpoint at the first bracket of your method is always the safest bet. :)
Groo
@Groo Thanks for the advice, I'll keep that in mind :-)
S.C. Madsen