Search code examples
c#debuggingvisual-studio-2017dotnetbrowser

DotNetBrowser DOMNode debugging


I am using DotNetBrowser, or at least trying to, and I am trying to get all of the checkboxes in a document.

public static void SetCodecSettings()
    {
        var waitEvent = new ManualResetEvent(false);
        _mf.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
        {
            if (e.IsMainFrame)
            {
                waitEvent.Set();
                var doc = _mf.Browser.GetDocument();
                var html = _mf.Browser.GetHTML();
                var checkBoxes = doc.GetElementsByTagName("input");
            }
        };
        _mf.Browser.LoadURL(_mf.PattonDeviceUrl + "/codecset.htm");
        waitEvent.WaitOne();
    }

When I put a breakpoint in, so I can inspect everything that is in checkBoxes, I get the following error when expanding checkBoxes in the debugger: enter image description here

I do not want to turn off the property evaluation because I want to inspect the contents of that item. Any suggestions on how to correct this?


Solution

  • The Chromium engine runs in a separate process. DotNetBrowser library uses multiple threads for exchanging data between the Chromium engine and the .NET side. Almost any evaluation involves IPC, because DotNetBrowser does not perform any data caching itself.

    When Visual Studio stops the application at some breakpoint, some of the DotNetBrowser threads are getting paused. In this case the library cannot obtain data and process requests from Chromium process. This is why you cannot evaluate expressions in the debugger.

    This issue is rather common when debugging multi-process applications, not only DotNetBrowser. As a workaround you can use logging to display required data at runtime.

    The following article explains the observed behavior:

    https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000117030--the-function-evaluation-requires-all-threads-to-run-message-in-debugger-or-quick-watch