Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

[DAM analyzer] Report DAM warnings for generics in all cases #2364

Closed

Description

@sbomer

This is a tracking issue for support for annotated generics in the analyzer. The DAM analyzer only validates annotations for generics at callsites to generic methods:

CheckAndReportDynamicallyAccessedMembers (targetMethod.TypeArguments[i], targetMethod.TypeParameters[i], context, invocationOperation.Syntax.GetLocation (), targetIsMethodReturn: false);

This needs to be extended to cover all type references which may reference generic instantiations, including:

  • base/interface types of a type declaration
  • variable declarations
  • field/property/event declarations
  • parameter/return types of methods

This is probably best done using the symbol-based callbacks (RegisterSymbolAction) rather than the IOperation-based ones.

I would start by enabling some of the tests in GenericParameterDataFlow (or temporarily copying them to DynamicallyAccessedMembersAnalyzerTests.cs if that's easier). For example DerivedTypeWithOpenGenericOnBase looks like a good starting point.

Activity

  1. sbomer commented on Nov 19, 2021

    @sbomer
    MemberAuthor

    Per @agocke's suggestion it might be better to do this using the syntax APIs which would likely cover all of the above cases (whereas using the symbol APIs would only get you callbacks for the symbol declarations and would require a separate approach for handling references to substituted generics inside method bodies).

  2. self-assigned this
    on Nov 29, 2021
  3. sbomer commented on Feb 1, 2022

    @sbomer
    MemberAuthor

    #2574 tracks the remaining work to get validation of array types passed as generic parameters. I think all of the other cases are now covered by #2478 so I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions