dotnet / dotnet/docs-desktop

WebBrowser interop API how-to example code does not work in .NET 5.0

Open
#169 1 comment 0 reactions 0 assignees View on GitHub
doc-bug dotnet-framework/svc okr-health okr-quality Pri2 winforms/subsvc
Dominant language
C#
Stars
237
Forks
191
Avg merge
4d 16h
Merged PRs (30d)
3

Description

This how-to contains example code that worked in .NET Core 3.1 but no longer works in .NET 5.0.

See dotnet/winforms#4443 for details.

I recognize this how-to page is only for .NET Framework 4.8, but there is no other version of this how-to, and WebBrowser is a supported API of both .NET Core 3.1 and .NET 5.0.

Please consider either (a) adding a "note" element in this how-to with a warning and explanation of the issue for .NET 5.0 or (b) create and appropriately update a copy of this how-to for .NET 5.0.

If it's useful to summarize here, the correct code for .NET 5.0 should either:

- (a) define an interface containing the signature of `Test`, add that interface to `Form1`'s declaration, then annotate `Form1` with `ComDefaultInterface`; or

- (b) extract `Test` to a new type, then assign an instance of that type to `ObjectForScripting` (instead of assigning `this`).

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: c586d0c9-fb61-4fb5-6f7b-2d1a8abc0dd4
* Version Independent ID: 5e8ef638-ba4d-4b78-b9b4-79e4732b77c8
* Content: [How to: Implement Two-Way Communication Between DHTML Code and Client Application Code - Windows Forms .NET Framework](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/implement-two-way-com-between-dhtml-and-client?view=netframeworkdesktop-4.8)
* Content Source: [dotnet-desktop-guide/framework/winforms/controls/implement-two-way-com-between-dhtml-and-client.md](https://github.com/dotnet/docs-desktop/blob/master/dotnet-desktop-guide/framework/winforms/controls/implement-two-way-com-between-dhtml-and-client.md)
* Product: **dotnet-framework**
* Technology: **dotnet-winforms**
* GitHub Login: @adegeo
* Microsoft Alias: **adegeo**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.