I'm porting a .NET application to Mono 2.6.7 and I'm having problems with a the web browser cont开发者_C百科rol. I made a separate project to try and recreate the issue.
I'm doing this:
public class Gui : System.Windows.Forms.Form {
public Gui() {
var browser = new System.Windows.Forms.WebBrowser();
this.Controls.Add(browser);
browser.Dock = System.Windows.Forms.DockStyle.Fill;
browser.DocumentText = "<html><body>1234</body></html>";
}
}
And it fails with this:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
at Mono.Mozilla.DOM.HTMLElement.set_OuterHTML (System.String value) [0x00000] in <filename unknown>:0
at System.Windows.Forms.WebBrowser.set_DocumentText (System.String value) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.WebBrowser:set_DocumentText (string)
at WebBrowserTest.Gui..ctor () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) WebBrowserTest.Gui:.ctor ()
at WebBrowserTest.SharpWiredMain..ctor () [0x00000] in <filename unknown>:0
at WebBrowserTest.SharpWiredMain.Main () [0x00000] in <filename unknown>:0
I have tried many different things and I think I got it to work with the DocumentStream but I would really prefer if I could use the DocumentText property.
What am I doing wrong?
This is how I made a temporary fix to this bug: code below: Instead of using the WebBrowser in your code, find and replace with MyWebBrowser derivative that you created.
public class MyWebBrowser : WebBrowser
{
public MyWebBrowser()
{
this.Disposed += new EventHandler(this_Disposed);
}
void this_Disposed(object sender, EventArgs e)
{
if (ms != null)
{
ms.Close();
ms.Dispose();
}
}
private MemoryStream ms = null;
private string _documentText = "";
public new string DocumentText
{
get
{
return _documentText;
}
set
{
try
{
_documentText = value;
byte[] documentData = System.Text.Encoding.Default.GetBytes(_documentText);
ms = new MemoryStream(documentData);
this.DocumentStream = ms;
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
You could try geckofx?
https://bitbucket.org/geckofx/geckofx/wiki/Home
精彩评论