[Mono-dev] Bug in System.Windows.Forms.WebBrowser

Quandary quandary82 at hailmail.net
Sat Apr 9 13:59:26 EDT 2011


I was trying to work around the problem that there is no SQL Syntax
highlighter that works for mono on Linux with WinForms.

As a workaround, I put the SQL editor in a WebBrowser window, setting
the initial page on Form_Load and then calling

            object objReturnValue =

to invoke a JavaScript function that returns me the text in the HTML
It works perfectly on Windows...
The HTML SQL editor works perfectly in FireFox, IE and Google
Chrome/WebKit, also on Linux.

But the problem is:
object objReturnValue =
returns ">" on the first run, and crashes when run for a second time...
It seems like InvokeScript is buggy.
It's not the Regex, I tested that by removing it, including the encoding

And another problem:
I tried doing that with webkit-sharp in a GTK project.
The problem there is that while you can invoke a void return type
JavaScript function - which works fine - , there's no way to get a
JavaScript function return value, such as a string, in webkit-sharp...

Used mono-version:
mono --version
Mono JIT compiler version 2.10.1 (tarball Sun Mar  6 21:19:00 CET 2011)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  x86
    Disabled:      none
    Misc:          softdebug
    LLVM:          supported, not enabled.
    GC:            Included Boehm (with typed GC and Parallel Mark)
root at IS1300-1:~#

uname -a
Linux IS1300-1 2.6.35-28-generic #49-Ubuntu SMP Tue Mar 1 14:40:58 UTC
2011 i686 GNU/Linux
root at IS1300-1:~#

Used code:

        public string Strip(string text)
            if (string.IsNullOrEmpty(text))
                return string.Empty;

            // Grrrrr
            text = System.Text.RegularExpressions.Regex.Replace(text,
@"currentText=""(\s+)?<(\s+)?""", string.Empty);
            text = System.Text.RegularExpressions.Regex.Replace(text,
@"currentText=""(\s+)?>(\s+)?""", string.Empty);
            // Ungrrrr

            text = System.Text.RegularExpressions.Regex.Replace(text,
@"<(.|\n)*?>", string.Empty);
            return text;
        } // End Function Strip
        public string GetSQLstatement()
            object objReturnValue =

            string broken = objReturnValue.ToString();
            byte[] encoded =
            string corrected = Encoding.UTF8.GetString(encoded);

            corrected = Strip(corrected);
            corrected = System.Web.HttpUtility.HtmlDecode(corrected);

            return corrected;
        } // End Function GetSQLstatement
        private void button1_Click(object sender, EventArgs e)
        } // End Sub button1_Click

System.Windows.Forms.WebBrowser wbSQLhighlighter;

and on Form_Load:
if(Environment.OSVersion.Platform == PlatformID.Unix)


where highlight.htm is

<html xmlns="http://www.w3.org/1999/xhtml" style="height: 100%;">
    <script src="../../js/codemirror.js" type="text/javascript"></script>
    <title>CodeMirror: SQL demonstration</title>
    <link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
<script language="javascript" >

function gimme(strMessage)
    return strMessage + strMessage;

function say(strMessage)

function sayHello()

function getSqlStatement()
    return getSQLtext();

function getSQLtext()
    var elements = document.getElementsByTagName("iframe");
    var objiFrame = elements[0];
    var str = objiFrame.contentWindow.document.body.innerHTML;
    if(str == null)
        return "NULL";
    //return "SELECT * FROM T_Benutzeräöü";
    // str = str.replace(/<.*?>/ig, "");
    // IE sucks, Chrome doesn't. Moving this to C#, problem solved ...
    str = str.replace(/<span.*?>/ig, "");
    str = str.replace(/<\/span.*?>/ig, "");
    str = str.replace(/<br.*?>/ig, "");
    return str;


  <body style="margin: 0px; padding: 0px; width: 100%; height: 100%;
overflow: hidden;">

<textarea id="code" cols="120" rows="50" style="margin: 0px; padding: 0px;">
SELECT table_name, view_definition FROM INFORMATION_SCHEMA.VIEWS

<script type="text/javascript">
  var editor = CodeMirror.fromTextArea('code', {
    height: "450px",
    parserfile: "../contrib/sql/js/parsesql.js",
    stylesheet: "css/sqlcolors.css",
    path: "../../js/",
    textWrapping: false
    <input type="button" onclick="alert(getSQLtext());" value="Get
command text" />


More information about the Mono-devel-list mailing list