Skip to content

Analyzer and Code-Fix to enable easy adoption of [GeneratedComInterface] #86343

Closed

Description

@jkoritzinsky

Describe the problem you are trying to solve

As part of the work to enable the new COM source generator, we want to make it easy to move from built-in COM to source-generated COM.

Describe suggestions on how to achieve the rule

  • Offer a code-fix to convert [ComImport] to [GeneratedComInterface] and remove shadowing methods that were required for inheritance in [ComImport].
  • Offer a code-fix to add [GeneratedComClass] to a class that implements a [GeneratedComInterface]-attributed type.
  • Report a diagnostic when a type with [ComVisible(true)] implements a [GeneratedComInterface]-attributed type and COM hosting is enabled.
    • A [GeneratedComInterface]-attributed type will not be exposed by built-in COM.
  • Report a diagnostic when a variable of a (compile-time) type or a typeof(T) that has either [GeneratedComInterface] or [GeneratedComClass] is passed to one of the following built-in COM interop-related methods:
    • These APIs will not work with the source-generated COM:
      • Marshal.SetComObjectData
      • Marshal.GetComObjectData
      • Marshal.ReleaseComObject
      • Marshal.FinalReleaseComObject
      • Marshal.CreateAggregatedObject
      • Marshal.CreateWrapperOfType
      • Marshal.GetTypedObjectForIUnknown
    • These APIs will work with source-generated COM if the user provides their own StrategyBasedComWrappers instance as a global marshalling instance. We do not recommend doing this unless it's a stopgap measure to assist migration.
      • Marshal.GetIUnknownForObject
      • Marshal.GetIUnknownForObjectInContext
      • Marshal.GetIDispatchForObject
      • Marshal.GetIDispatchForObjectInContext
      • Marshal.GetComInterfaceForObject
      • Marshal.GetTypedObjectForIUnknown

Additional context

Activity

  1. added
    api-suggestion
    code-analyzer
    code-fixer
    on May 16, 2023
  2. added this to the 8.0.0 milestone on May 16, 2023
  3. added
    api-ready-for-review
    and removed
    api-suggestion
    on May 18, 2023
  4. terrajobst commented on May 30, 2023

    @terrajobst
    Contributor

    Video

    Looks good as proposed

  5. added
    api-approved
    and removed
    api-ready-for-review
    on May 30, 2023
  6. ghost added
    in-pr
    on Jun 7, 2023
  7. ghost removed
    in-pr
    on Jun 9, 2023
  8. ghost locked as resolved and limited conversation to collaborators on Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Runtime.InteropServicescode-analyzercode-fixer

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions