Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

MA0093's scope was ambiguous—users expected it to flag all null EventArgs parameters, but it only triggers when raising events via delegate invocation.

Changes

  • Updated rule title: "EventArgs should not be null when raising an event"
  • Added explicit scope description to documentation
  • Enhanced code example to demonstrate regular methods are not flagged:
class Test
{
    public event EventHandler MyEvent;

    void OnEvent()
    {
        MyEvent.Invoke(this, null);        // MA0093: flagged
        MyEvent.Invoke(this, EventArgs.Empty); // ok
        
        RegularMethod(null);               // not flagged by MA0093
    }

    void RegularMethod(EventArgs args) { }
}

The analyzer behavior is unchanged—only documentation was updated to clarify the rule applies exclusively to event delegate invocations (.Invoke() calls on events), not arbitrary methods accepting EventArgs.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.nuget.org
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Release/net10.0/Meziantou.Analyzer.Test.runtimeconfig.json --depsfile /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Release/net10.0/Meziantou.Analyzer.Test.deps.json /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Release/net10.0/testhost.dll --port 34827 --endpoint 127.0.0.1:034827 --role client --parentprocessid 4725 --datacollectionport 34679 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[F.Rq.] Equivalent of MA0093 but for arguments to regular method</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
MA0093 only flags when an event is 'raised' with (EventArgs?) null, not just any time a null literal of type EventArgs? appears. I now see the intent behind the rule but for a while I just assumed that it wasn't working in our codebase.

Describe the solution you'd like
Please clarify the rule's title and documentation.
Alternatively, check arguments to regular methods too, but I could always write my own Analyzer for that. Let me know if you'd be interested in having it in this project.

Describe alternatives you've considered
N/A

Additional context
N/A</issue_description>

<agent_instructions>Can you update the documentation to describe the current behavior?</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@meziantou The rule only reports when invoking a delegate with 2 parameters and the second is of type `EventArgs`. There are many other valid use-cases, so it would report many false-positive in existing codebases.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Update documentation for MA0093 behavior Clarify MA0093 only applies to event invocations, not regular method calls Nov 21, 2025
Copilot AI requested a review from meziantou November 21, 2025 19:00
@meziantou meziantou marked this pull request as ready for review November 21, 2025 19:19
@meziantou meziantou merged commit 1d5bcd1 into main Nov 21, 2025
13 checks passed
@meziantou meziantou deleted the copilot/update-documentation-for-ma0093 branch November 21, 2025 19:20
This was referenced Nov 21, 2025
This was referenced Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[F.Rq.] Equivalent of MA0093 but for arguments to regular method

2 participants