Skip to content

Analyzer processes expression tree construction data flow differently from linker #3172

Description

@vitek-karas

For example:

			public static void MethodWithSingleAnnotatedParameter (
				[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type)
			{ }

			static void LdToken ()
			{
                                // Linker produces IL2111
                                // Analyzer produces IL2067
				Expression<Action<Type>> _ = (Type t) => MethodWithSingleAnnotatedParameter (t);

                                // Linker produces IL2111
                                // Analyzer doesn't warn
				Expression<Action> _ = () => MethodWithSingleAnnotatedParameter (typeof(string));
			}

The difference is because linker sees ldtoken and not an actual call and doesn't perform true data flow, but analyzer sees this as a normal statement and processes it through data flow.
The linker behavior is correct here, under the hood this creates expression tree with MethodInfo which is publicly accessible. And anybody with the expression tree can invoke the MethodInfo with any input. So this needs to warn always, regardless of data flow.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions