Unhandled exception using webBrowser

Hi,

I hade unhandled exception using WebBrowser and it is easy to emulate the problem. Just 2 form, and on Form2 a webbrowser component, this code on a button:


privatevoid button1_Click(object sender, EventArgs e)
{
Form2 F =new Form2();
F.ShowDialog();
}

When program close unhandled exception:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Is this a problem with WebBrowser in beta2 ?

[826 byte] By [WilfriedMestdagh] at [2008-2-15]
# 1
This is a known bug and is fixed in builds later than Beta 2:
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=3760eca5-3c11-4a82-872b-92418ff2d290

To work around this, simply correctly make sure that the form that hosts the WebBrowser control is disposed of so that WebBrowser control is also disposed.
For example your example above should be changed to:


private void button1_Click(object sender, EventArgs e)
{
using (Form2 = new Form2())
{
f.ShowDialog();
}
}

DavidM.Kean at 2007-9-7 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
David,
Do you know what the equivalent syntax would be in VB ?



Private Sub button1_Click(Byval sender as Object, Byval e as EventArgs)
Dim f as Form2 = New Form2
f.ShowDialog
End Sub


ie How do I make sure the form that hosts the Webbrowser control is disposed ?
wilfridB

WilfridB at 2007-9-7 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Try this:



Using f as New Form2()
f.ShowDialog()
End Using

DavidM.Kean at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
David,

I may be wrong but "using" is not a keyword in VB.
May be something like the following would do?


Dim f As New Form2
Try
f.ShowDialog()
Finally
f.Dispose()
End Try


wilfridB

I was wrong actually. "Using" IS a VB keyword and the funny thing is that :

Using obj
'do something with obj
End Using

is functionaly similar to

Try
'do something with obj
Finally
obj.dispose
End Try


WilfridB

WilfridB at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5

Can I ask you where your event handler is for this click?

MattSipes at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6

Hi,

Maybe it is a problem of WebBrowser beta 2.

I have tested the code with Visual C# 2003. No problem.

Have a fun!

Valentin

Do not hesitate to contact me!

www.wwv-it.eu

Valentin at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...