Skip to content

Commit f43b0c1

Browse files
authored
Pass through ComWrappers based objects to COM type descriptor (#89887)
WinForms hosts the the COM type descriptor. It has been updated to work with ComWrappers based objects- adding the check for them in TypeDescriptor. There are hard dependencies on Windows in the current implementation. We can potentially update to conditionalize these. dotnet/winforms#9291 tracks. There is no automated test as it would require adding a dependency upstream to WinForms.
1 parent f447532 commit f43b0c1

File tree

1 file changed

+12
-0
lines changed
  • src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel

1 file changed

+12
-0
lines changed

src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Diagnostics.CodeAnalysis;
99
using System.Globalization;
1010
using System.Reflection;
11+
using System.Runtime.InteropServices;
1112
using System.Threading;
1213

1314
namespace System.ComponentModel
@@ -1541,6 +1542,17 @@ private static TypeDescriptionNode NodeFor(object instance, bool createDelegator
15411542
{
15421543
type = ComObjectType;
15431544
}
1545+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
1546+
&& ComWrappers.TryGetComInstance(instance, out nint unknown))
1547+
{
1548+
// ComObjectType uses the Windows Forms provided ComNativeDescriptor. It currently has hard Win32
1549+
// API dependencies. Even though ComWrappers work with other platforms, restricting to Windows until
1550+
// such time that the ComNativeDescriptor can handle basic COM types on other platforms.
1551+
//
1552+
// Tracked with https://github.com/dotnet/winforms/issues/9291
1553+
Marshal.Release(unknown);
1554+
type = ComObjectType;
1555+
}
15441556

15451557
if (createDelegator)
15461558
{

0 commit comments

Comments
 (0)