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.

Adding RequiresAssemblyFiles in an Event does not suppress the warning #2005

Closed

Description

@tlakollo

Using the following code:

using System;
using System.Diagnostics.CodeAnalysis;

public class C
{
    [RequiresAssemblyFiles(Message = "message")]
    public int M1() => 0;

    public event EventHandler E1
    {
        add
        {
            var a = M1();
        }
        remove { }
    }
}

Should lead to a warning in the add event property, which later on should be able to be suppressed by adding an attribute to the event, like:

using System;
using System.Diagnostics.CodeAnalysis;

public class C
{
    [RequiresAssemblyFiles(Message = "message")]
    public int M1() => 0;

    [RequiresAssemblyFiles()]
    public event EventHandler E1
    {
        add
        {
            var a = M1();
        }
        remove { }
    }
}

The RequiresAssemblyFiles will continue to warn in the var a = M1(); assign operation, contrary to the use of UnconditionalSuppressMessage which will silence the warning

Activity

  1. self-assigned this
    on Apr 29, 2021
  2. added a commit that references this issue on May 5, 2021
    4a98616
  3. added a commit that references this issue on May 12, 2021
    2add126
  4. added a commit that references this issue on Nov 16, 2022
    bf3708c
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