Skip to content

Commit

Permalink
Pass through ComWrappers based objects to COM type descriptor (#89887)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JeremyKuhne committed Aug 3, 2023
1 parent f447532 commit f43b0c1
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;

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

if (createDelegator)
{
Expand Down

0 comments on commit f43b0c1

Please sign in to comment.