question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"window.external" evaluation in WebBrowser control gives error "Unexpected call to method or property access."

See original GitHub issue
  • .NET Core Version: .NET 5.0.101
  • Have you experienced this same bug with .NET Framework?: No.

Problem description:

As of .NET 5.0, the “window.external” object reference that’s intended to provide access to the WebBrowser.ObjectForScripting property value does not work. It worked in .NET Core 3.1.

I didn’t find any information about this behavior in the .NET 5 documentation for Breaking Changes or Known Issues.

Evaluating “window.external” in the control’s browser environment produces the following error message:

“Unexpected call to method or property access.”

Here’s a screenshot of the error:

webbrowser control error

Expected behavior:

A “normal” message box should show (with the message “called from script code”).

Minimal repro:

https://github.com/rummelsworth/WebBrowserControlTutorial

The above-linked repo is an implementation of the WebBrowser control’s “2-way communication” tutorial. It has 3 branches:

  • One branch targets netcoreapp3.1 and does not reproduce the error.
  • The main branch targets net5.0 and reproduces the error.
  • Another branch also targets net5.0 but has been migrated to use WebView2 instead of WebBrowser.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rummelsworthcommented, Jan 14, 2021

@RussKie I think the links are visible above my previous comment in the GitHub UI but probably not included in the notification emails. Here are the links:

Thanks again.

1reaction
RussKiecommented, Jan 13, 2021

I bisected it, and it looks like we regressed in #3388.

@weltkante looks like not all ComVisible attributes were incorrect after all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

.NET 5.0 System.Windows.Forms.WebBrowser " ...
Evaluating “window.external” in the control's browser environment produces the following error message: “Unexpected call to method or property ...
Read more >
window.external throwing error (Unexpected call to method ...
I am using WebBrowser control in WinForm Application. When it hits the external method then it gives following error"Error: Unexpected call ...
Read more >
About Error 2147418113 Unexpected Call to Method Or ...
The error message refers to an "Unexpected Call to Method Or Property Access". That would indicate that the error is caused by calling...
Read more >
eval() - JavaScript - MDN Web Docs - Mozilla
The eval() function evaluates JavaScript code represented as a string and returns its completion value. The source is parsed as a script.
Read more >
JavaScript policy runtime error troubleshooting | Apigee
The error type RangeError is thrown when you operate on a value or pass a value to a function that is not in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found