Skip to content

Commit 3dec7d7

Browse files
authored
Merge pull request #12341 from dotnet/backport/pr-12333-to-release/9.0
[release/9.0] Fix ConnectionPointCookie usages
2 parents 29c6dff + 3f83367 commit 3dec7d7

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/AxHost.OleInterfaces.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal void StartEvents()
5656
}
5757

5858
object? nativeObject = _host.GetOcx();
59-
_connectionPoint = new ConnectionPointCookie(nativeObject, this, typeof(IPropertyNotifySink), throwException: false);
59+
_connectionPoint = new ConnectionPointCookie(nativeObject, this, typeof(IPropertyNotifySink.Interface), throwException: false);
6060
}
6161

6262
internal void StopEvents()

src/System.Windows.Forms/src/System/Windows/Forms/Controls/WebBrowser/WebBrowserSiteBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,18 @@ internal void StartEvents()
381381
{
382382
try
383383
{
384-
_connectionPoint = new AxHost.ConnectionPointCookie(nativeObject, this, typeof(IPropertyNotifySink));
384+
_connectionPoint = new AxHost.ConnectionPointCookie(nativeObject, this, typeof(IPropertyNotifySink.Interface));
385385
}
386+
#if DEBUG
387+
catch (Exception)
388+
{
389+
throw;
390+
}
391+
#else
386392
catch (Exception ex) when (!ex.IsCriticalException())
387393
{
388394
}
395+
#endif
389396
}
390397
}
391398

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHostTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,6 +3085,18 @@ public unsafe void AxHost_Ocx_Dispose_Success()
30853085
(ocx.Value->Release() - 1).Should().Be(0);
30863086
}
30873087

3088+
[WinFormsFact]
3089+
public unsafe void AxHost_Ocx_ConnectionPoint_Success()
3090+
{
3091+
using SubAxHost control = new(WebBrowserClsidString);
3092+
control.CreateControl();
3093+
3094+
object site = control.TestAccessor().Dynamic._oleSite;
3095+
AxHost.ConnectionPointCookie cookie = site.TestAccessor().Dynamic._connectionPoint;
3096+
cookie.Should().NotBeNull();
3097+
cookie.Connected.Should().BeTrue();
3098+
}
3099+
30883100
private class SubComponentEditor : ComponentEditor
30893101
{
30903102
public override bool EditComponent(ITypeDescriptorContext context, object component)

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/WebBrowserTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,4 +4751,32 @@ private class SubWebBrowser : WebBrowser
47514751

47524752
public new void WndProc(ref Message m) => base.WndProc(ref m);
47534753
}
4754+
4755+
[WinFormsFact]
4756+
public void WebBrowser_NavigateToFileFolder()
4757+
{
4758+
using Form form = new();
4759+
using WebBrowser browser = new()
4760+
{
4761+
Dock = DockStyle.Fill
4762+
};
4763+
4764+
string navigated = null;
4765+
browser.Navigated += (sender, e) =>
4766+
{
4767+
navigated = browser.Url.ToString();
4768+
form.Close();
4769+
};
4770+
4771+
form.Controls.Add(browser);
4772+
4773+
form.Load += (sender, e) =>
4774+
{
4775+
browser.Navigate(@"file://C:/");
4776+
};
4777+
4778+
form.Show();
4779+
4780+
navigated.Should().Be(@"file:///C:/");
4781+
}
47544782
}

0 commit comments

Comments
 (0)