Skip to content

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

@jkoritzinsky

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.Runtime.InteropServicescode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixer

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions