Skip to content

Commit 94734db

Browse files
authored
Merge pull request #12342 from lonitra/backport12333
[release/8.0] Fix ConnectionPointCookie usages
2 parents 579c090 + a192d4d commit 94734db

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/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/WebBrowserSiteBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,18 @@ internal void StartEvents()
384384
{
385385
try
386386
{
387-
connectionPoint = new AxHost.ConnectionPointCookie(nativeObject, this, typeof(IPropertyNotifySink));
387+
connectionPoint = new AxHost.ConnectionPointCookie(nativeObject, this, typeof(IPropertyNotifySink.Interface));
388388
}
389+
#if DEBUG
390+
catch (Exception)
391+
{
392+
throw;
393+
}
394+
#else
389395
catch (Exception ex) when (!ex.IsCriticalException())
390396
{
391397
}
398+
#endif
392399
}
393400
}
394401

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
Assert.Equal((uint)0, ocx.Value->Release() - 1);
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+
Assert.NotNull(cookie);
3097+
Assert.True(cookie.Connected);
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
@@ -4742,4 +4742,32 @@ private class SubWebBrowser : WebBrowser
47424742

47434743
public new void WndProc(ref Message m) => base.WndProc(ref m);
47444744
}
4745+
4746+
[WinFormsFact]
4747+
public void WebBrowser_NavigateToFileFolder()
4748+
{
4749+
using Form form = new();
4750+
using WebBrowser browser = new()
4751+
{
4752+
Dock = DockStyle.Fill
4753+
};
4754+
4755+
string navigated = null;
4756+
browser.Navigated += (sender, e) =>
4757+
{
4758+
navigated = browser.Url.ToString();
4759+
form.Close();
4760+
};
4761+
4762+
form.Controls.Add(browser);
4763+
4764+
form.Load += (sender, e) =>
4765+
{
4766+
browser.Navigate(@"file://C:/");
4767+
};
4768+
4769+
form.Show();
4770+
4771+
Assert.Equal(@"file:///C:/", navigated);
4772+
}
47454773
}

0 commit comments

Comments
 (0)