locked
How to catch this exception RRS feed

  • Question

  • Hello,

    I have a WPF application I am developing for a company that has a webbrowser hosted in a windows forms host.  I have been getting a particular error from several users that I can't figure out how to take care of.  Worse still, I don't know for sure where it is coming from.  The exception is:  Invisible or disabled control cannot be activated.  The stack trace has calls like "System.Windows.Forms.ContainerControl.SetActiveControlInternal(), and since the webbrowser is basically the only windows forms control in the entire project, I assume it is stemming from it. 

    If the user is inactive for an extended period, I display a sort of login screen.  To do this, I have to hide the webbrowser since .net 2.0 controls and .net 3.0 controls can't share the same screen space.  I image this is where the invisible or disabled control part of the exception is coming from.  I can't really figure out what could be trying to activate the control however.  The only thing I could think of was maybe some Javascript function might be trying to set focus to the page in the browser.  Could this be causing this problem?  Either way, how do I catch an exception like this?  I don't know what I would wrap the try catch around.

    Thanks for any suggestions.
    Jarrod
    Thursday, July 5, 2007 5:33 PM

Answers

  •  

    Creating new instance of WindowsFormHost whenever child need to be changed resolved the problem for me.
    Tuesday, May 20, 2008 6:35 AM

All replies

  • You could try this:

    Application.DispatcherUnhandledException
    " Occurs when an exception is raised by the application but not handled."

    As an experiment, try moving the browser off the form (-1000, -1000 for example) rather than hiding or disabling it. Does the problem continue to happen?

    It is probably trying to activate due to some activity within the control.
    Friday, July 6, 2007 12:46 AM
  • I am going to try the moving the browser thing... thats a good idea.  I will just have to make the change and let some people use it for a while to see if it is helping. 

    I failed to mention in my original post, I have handlers attached to both Application.DispatcherUnhandledException and Appdomain.UnhandledException.  The strange thing is, this particular error is not caught by either of those.  I imagine it is because this is a windows forms control.  Can anybody tell me for sure why, or a better way to catch an error like this?

    Jarrod
    Friday, July 6, 2007 3:07 PM
  • Nope, that didn't do it.  I got the same exception today.  The main problem I have is that I never get the exception here on my development machine.  Its always somebody here in the office, and I have no debugging capabilities. The exception doesn't give any line numbers so I have no idea exactly where it is coming from.  Is JIT debugging helpful at all in situations like this?  And if so, how do you enable it for WPF applications?
    Monday, July 9, 2007 10:27 PM
  • Can you post a complete callstack?

    You can try running the application always under a debugger and possibly also set the debugger to stop on first-chance exceptions:

    1. Install Debugging Tools for Windows: http://www.microsoft.com/whdc/devtools/debugging/default.mspx
    2. Save the following in a .reg file and import it (or manually create the key):

    Windows Registry Editor Version 5.00

     

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\YourAppName.exe]
    "Debugger"="c:\\debuggers\\cdb.exe -gG"

    Since the debugger automatically starts and shuts down with the application, this setup should be minimally disruptive to your users. If something catches the exception internally before it's reported, you can set the debugger to break on first-chance exception. Replace the parameters to cdb.exe with -c "sxe clr; g" -G .

    For the basics of debugging managed code with CDB/WinDbg, see here: http://blogs.msdn.com/vancem/archive/2006/09/05/742062.aspx#742937. Getting a callstack (!clrstack) is one of the easiest and most useful things to do. Also, you could save a dump of the process and let us take a look. The command is .dump /ma filename.dmp.

    Tuesday, July 17, 2007 2:06 AM
  • Anybody able to resolve this exception?

    Friday, May 16, 2008 10:55 AM
  •  

    Creating new instance of WindowsFormHost whenever child need to be changed resolved the problem for me.
    Tuesday, May 20, 2008 6:35 AM