Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch PNSE in TypeDescriptor #90550

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,7 @@ private static TypeDescriptionNode NodeFor(object instance, bool createDelegator
{
type = ComObjectType;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
&& ComWrappers.TryGetComInstance(instance, out nint unknown))
else if (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
Expand Down Expand Up @@ -2538,6 +2537,23 @@ public static void SortDescriptorArray(IList infos)
ArrayList.Adapter(infos).Sort(MemberDescriptorComparer.Instance);
}

/// <summary>
/// Wraps ComWrappers.TryGetComInstance and returns false when not supported
/// </summary>
private static unsafe bool TryGetComInstance(object instance, out IntPtr unknown)
{
unknown = IntPtr.Zero;
try
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
ComWrappers.TryGetComInstance(instance, out unknown);
}
catch (PlatformNotSupportedException)
{
return false;
}
}

/// <summary>
/// This class is a type description provider that works with the IComNativeDescriptorHandler
/// interface.
Expand Down