Why does invalid handle exception occur when browsing via WPF WebBrowser control? - wpf

I have a WPF app that has a window with a WebBrowser control in it. I navigate to a site like http://www.cnn.com, it loads, and then I get an error when I click a link. This only happens when debugging on a Windows Server VM that has VS 2010 on it. Running the compiled app out of the bin or debugging on my Win7 machine works fine.
With unmanaged debugging off you just get the vshost32.exe has stopped working. The specific error seen if I enable unmanaged debugger is an "invalid handle exception".
Any thoughts on what to look for between the two environments or why this would happen?

Related

Exceptions in WPF Word Addin are not being handled

I am creating a WPF Office add in, and I would like to handle all exceptions in one place. To do this I use the following code in the constructor of my MainWindowViewModel:
Dispatcher.CurrentDispatcher.UnhandledExceptionFilter += new
DispatcherUnhandledExceptionFilterEventHandler(HandleAllException);
In my test environment I host the WPF app from a console application project, and exceptions are handled as expected. When I host the WPF app from within word however, nothing happens when exceptions are thrown. There is no notification at all that there has even been an exception, other than in the output window in visual studio. Does anyone have any suggestions as to what I might be doing wrong?
I have solved the problem by changing the way in which I launch my WPF app. I believe the problem was related to this.

WPF Designer Never Loads Properly

I have an WPF app, all seems to run fine with one exception - the designer rarely, if ever, loads correctly. Usually complaining about Undefined CLR namespace. and then saying it can't find a few of my local: defined controls.
Is this just a defect in the designer or Visual Studios code generation or actually systemic of something wrong with my application?
In your code can be an error which occurs only in design time. It is possible to debug it. See How to: Debug a Designer Load Failure. Shortly you need another instance of Visual Studio and attach it to the one displaying your wpf app. You can even try to follow the error to its roots with How to: Debug .NET Framework Source.
I had a similar problem and I successfully tracked it down to DataContextChanged event handler and got rid of it.

Returning the control back from the JIT debugger to the application

I am having trouble with the JIT Debugger. I have a windows forms application which calls into a .NET assembly which has a function called calc(int,int) which has a break point set using the System.Debugger.Break(). This assembly is loaded when I click on a button in the forms application. Now, when the breakpoint is hit the JIT debugger asks me if I want to debug the application. I choose to do so and select a current instance of visual studio which has the project for the forms application I was running loaded. VS successfully breaks at this call. Now when I click on run I expected the forms application to return to a state where I can interact with it again.Instead, what I get is a "ghost" window of the forms application. Is there anyway to get around this problem? I know attaching the forms application to the VS debugger before the breakpoint is one solution. But is there any way to get this behavior when I use the JIT debugger?
Thank You.

Silverlight debugging; not attaching process

I use Google Chrome as my default browser but prefer to use Internet Explorer for debugging Silverlight applications. I therefore set my web project properties thus and check the Silverlight debugger option.
This has worked fine for ages but since returning from vacation I find that the iexplore.exe process running silverlight is no longer attached to the debugger and I must attach it manually. When not debugging my app I can check the Debug | Attach to Process... dialog and see that there are no instances of iexplore.exe running. Then I hit F5 and start a debug session and look again, after which there are two instances, one of which is attached, but not the one running Silverlight. Once I attach the other too, debugging works fine and I can hit breakpoints and step through the code with no problem.
Any ideas on what I'm missing to get the debugger attaching to the correct process would be appreciated.
Chrome is my default OS browser, but I use IE for SL debugging.
What I do is find the ASPX page in the hosting Web project in the solution view of Visual Studio. Right-click the file and select Browse With. You'll be presented with a dialog. Select IE from this list of Browsers and press the Set as Default button. I then cancel out of this dialog. Now when VS starts debugging it uses IE! You'll need to undo your "Start external program" debugging options in the project (switch back to Current/Specific Page).
VS will occasionally "forget" this setting and switch it back to Chrome. Just repeat this process.

How to prevent Just-In-Time Debugger showing when script error occurs in WebBrowser control

I use a WebBrowser control in my Winforms application. When I navigate to a Url that causes a JavaScript exception the Just-In-Time (JIT) debugger window shows up asking if you want to debug this exception:
An Unhandled exception ('Object
expected') occured in (application)
This happens (in Release mode) even though I set the ScriptErrorsSuppressed on the WebBrowser control to True. I could only reproduce the issue when Visual Studio was installed so I assume that the JIT debugger catches the exception and then ask if you want to Debug.
How can I prevent this from happening? What I am trying to do is catch the exception or disable JIT debugging for my application without having to reconfigure IE or Visual Studio.
Some of our users have Visual Studio installed and these JIT popups make our application unusable.
See this link for how to disable the JIT debugger. The short version is open Visual Studio as an Admin and navigate to Tools -> Options -> Debugger -> JIT Debugging
http://msdn.microsoft.com/en-us/library/k8kf6y2a.aspx

Resources