Skip to content

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

@tlakollo

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions