{"id":2624,"date":"2022-08-30T15:26:25","date_gmt":"2022-08-30T15:26:25","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/04\/how-to-return-the-json-of-a-javascript-object-in-a-wpf-application-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:25","modified_gmt":"2022-08-30T15:26:25","slug":"how-to-return-the-json-of-a-javascript-object-in-a-wpf-application-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-return-the-json-of-a-javascript-object-in-a-wpf-application-collection-of-common-programming-errors\/","title":{"rendered":"how to return the JSON of a javascript object in a WPF application-Collection of common programming errors"},"content":{"rendered":"<p>I have a WPF app with a WebBrowser control<\/p>\n<p>I need to get the JSON string of a javascript object, something like this:<\/p>\n<pre><code>var json = this.WebBrowser.InvokeScript(\"eval\", new object[] { \"JSON.stringify(window.mainThing)\" }); \n<\/code><\/pre>\n<p>I am executing this code on WebBrowser&#8217;s LoadCompleted event<\/p>\n<p>this throws an exception<\/p>\n<p>System.Runtime.InteropServices.COMException was unhandled by user code<\/p>\n<pre><code>  HResult=-2147352319\n  Message=Exception from HRESULT: 0x80020101\n  Source=WindowsBase\n  ErrorCode=-2147352319\n  StackTrace:\n       at MS.Internal.Interop.HRESULT.ThrowIfFailed(String message)\n       at System.Windows.Controls.WebBrowser.InvokeScript(String scriptName, Object[] args)\n<\/code><\/pre>\n<p>Here&#8217;s the Javascript in the page:<\/p>\n<blockquote>\n<pre><code>\n   window.mainThing = { x : 1 };\n\n<\/code><\/pre>\n<\/blockquote>\n<p id=\"rop\"><small>Originally posted 2014-02-04 09:55:00. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a WPF app with a WebBrowser control I need to get the JSON string of a javascript object, something like this: var json = this.WebBrowser.InvokeScript(&#8220;eval&#8221;, new object[] { &#8220;JSON.stringify(window.mainThing)&#8221; }); I am executing this code on WebBrowser&#8217;s LoadCompleted event this throws an exception System.Runtime.InteropServices.COMException was unhandled by user code HResult=-2147352319 Message=Exception from HRESULT: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2624","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2624"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2624\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}