2011-02-28 2 views
0

.NET 응용 프로그램을 Mono 2.6.7로 이식하고 있는데 웹 브라우저 컨트롤에 문제가 있습니다. 문제를 재현하기 위해 별도의 프로젝트를 만들었습니다.DocumentText를 사용하여 모노로 Forms.WebBrowser에 문자열 설정

나는이 일을 해요 :

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>"; 
    } 
} 

를 그리고이 실패 : 나는 많은 다른 것들을 시도하고 난 내가 DocumentStream와 함께 작동하도록 그것을 가지고하지만 난 것이라고 생각

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 

DocumentText 속성을 사용할 수 있다면 정말 좋습니다.

내가 뭘 잘못하고 있니?

+0

이 모노 버그가 이미 https://bugzilla.novell.com/show_bug.cgi?id=640411 너무 나쁜 것처럼 보인다 :( – Ola

답변

0

다음은 코드 ( )의 임시 수정 방법입니다. 코드에서 WebBrowser를 사용하는 대신 작성한 MyWebBrowser 파생어를 찾아서 바꾸십시오.

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); 
      } 
     } 
    } 
}