Skip to content

Annotate unsupported APIs in Runtime.InteropServices #50524

Closed

Description

@buyaa-n

As part of #47228 i am running an analyzer to detect APIs throwing PNSE but not annotated with Obsolete/SupportedOSPlatform/UnsupportedOSPlatform attributes, we need to annotate them so that developers get warnings when they use them unexpectedly

For now, I have results only cross-platform and .Net 5.0 or higher builds, analysis of targeted builds or lower env are coming soon where more APIs could be detected

Location API Comment Suggestion
ExpandoToDispatchExMarshaler.cs(32,13) 'MarshalManagedToNative(object)' unconditionally throws on all platforms add [Obsolete]
ExpandoToDispatchExMarshaler.cs(37,13) 'MarshalNativeToManaged(IntPtr)' unconditionally throws on all platforms add [Obsolete]
TypeToTypeInfoMarshaler.cs(32,13) 'MarshalManagedToNative(object)' unconditionally throws on all platforms add [Obsolete]
TypeToTypeInfoMarshaler.cs(37,13) 'MarshalNativeToManaged(IntPtr)' unconditionally throws on all platforms add [Obsolete]
RuntimeEnvironment.cs(11,57) 'SystemConfigurationFile.get' unconditionally throws on all platforms add [Obsolete]
RuntimeEnvironment.cs(25,84) 'GetRuntimeInterfaceAsIntPtr(Guid, Guid)' unconditionally throws on all platforms add [Obsolete]
RuntimeEnvironment.cs(27,84) 'GetRuntimeInterfaceAsObject(Guid, Guid)' unconditionally throws on all platforms add [Obsolete]

Note: We are suggesting to add [Obsolete] with the corresponding message for APIs supported in .Net framework but not supported in .NetCore, if it is only supported on a specific platform(s) consider adding [SupportedOSPlatform("platformName")] or if it is unsupported on a specific platform(s) [UnsupportedOSPlatform("platformName")] attribute instead

cc @jeffhandley @terrajobst @GrabYourPitchforks

Activity

  1. added this to the 6.0.0 milestone on Mar 31, 2021
  2. ghost added
    untriaged
    on Mar 31, 2021
  3. removed
    untriaged
    on Apr 2, 2021
  4. AaronRobinsonMSFT commented on Apr 2, 2021

    @AaronRobinsonMSFT
    Member

    @buyaa-n Both ExpandoToDispatchExMarshaler and TypeToTypeInfoMarshaler are now internal and not in any reference assembly. This can be verified in the official documentation as they don't show up in .NET5+.

  5. ghost added
    in-pr
    on Apr 2, 2021
  6. buyaa-n commented on Apr 3, 2021

    @buyaa-n
    ContributorAuthor

    Thanks, @AaronRobinsonMSFT, yes internal/private APIs are optional, I included them because they might used/referenced in public APIs and those public APIs might need further attention like being annotated with Obsolete or so

  7. ghost removed
    in-pr
    on Apr 3, 2021
  8. ghost locked as resolved and limited conversation to collaborators on May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions