Skip to content

Commit

Permalink
[release/8.0] Return false from ComWrappers.Try... methods (#90635)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
github-actions[bot] and jkotas authored Aug 16, 2023
1 parent bec2670 commit b33c596
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ private static TypeDescriptionNode NodeFor(object instance, bool createDelegator
{
type = ComObjectType;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
else if (OperatingSystem.IsWindows()
&& ComWrappers.TryGetComInstance(instance, out nint unknown))
{
// ComObjectType uses the Windows Forms provided ComNativeDescriptor. It currently has hard Win32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public abstract partial class ComWrappers
{
public static unsafe bool TryGetComInstance(object obj, out IntPtr unknown)
{
throw new PlatformNotSupportedException();
unknown = default;
return false;
}

public static unsafe bool TryGetObject(IntPtr unknown, [NotNullWhen(true)] out object? obj)
{
throw new PlatformNotSupportedException();
obj = default;
return false;
}

public partial struct ComInterfaceDispatch
Expand Down

0 comments on commit b33c596

Please sign in to comment.