Skip to content

Commit b33c596

Browse files
[release/8.0] Return false from ComWrappers.Try... methods (#90635)
* Return false from ComWrappers.Try... methods Return false from ComWrappers.TryGetComInstance/TryGetObject instead of throwing PNSE. It saves callers from needing to protect against PNSE. Fix #90311 * More efficient IsWindows check --------- Co-authored-by: Jan Kotas <[email protected]>
1 parent bec2670 commit b33c596

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ private static TypeDescriptionNode NodeFor(object instance, bool createDelegator
15421542
{
15431543
type = ComObjectType;
15441544
}
1545-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
1545+
else if (OperatingSystem.IsWindows()
15461546
&& ComWrappers.TryGetComInstance(instance, out nint unknown))
15471547
{
15481548
// ComObjectType uses the Windows Forms provided ComNativeDescriptor. It currently has hard Win32

src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ public abstract partial class ComWrappers
1111
{
1212
public static unsafe bool TryGetComInstance(object obj, out IntPtr unknown)
1313
{
14-
throw new PlatformNotSupportedException();
14+
unknown = default;
15+
return false;
1516
}
1617

1718
public static unsafe bool TryGetObject(IntPtr unknown, [NotNullWhen(true)] out object? obj)
1819
{
19-
throw new PlatformNotSupportedException();
20+
obj = default;
21+
return false;
2022
}
2123

2224
public partial struct ComInterfaceDispatch

0 commit comments

Comments
 (0)