Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

When typing await in an event handler, the completion provider was changing void to Task, breaking event handler signatures that must return void.

Example:

public class C
{
    public event EventHandler MyEvent;
    
    public C() => MyEvent += OnMyEvent;
    
    private void OnMyEvent(object sender, EventArgs e)
    {
        await... // Was: async Task OnMyEvent ❌ Now: async void OnMyEvent ✅
    }
}

Changes

  • Detection logic: Added IsMethodUsedAsEventHandler to scan containing type for event += Method patterns using semantic model
  • Return type preservation: Modified GetReturnTypeChange to skip void → Task conversion when method is detected as event handler
  • Test coverage: Added unit tests for various event registration patterns (+=/-=, custom delegates, registration locations) and integration tests validating actual completion behavior

Regular methods without event registration continue converting void → Task as expected.

Original prompt

This section details on the original issue you should resolve

<issue_title>C# editor breaking change in behavior when writing await keyword inside event handler</issue_title>
<issue_description>This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version] [regression] [worked-in:17.9]
when writing await in an event handler, the return type is changed from
private void
to
private async Task
This is new behavior and it will make the project uncompilable. Event cannot have async Task event handler.

Previous behavior: when writnig await inside method, async keyword is added to method signature

obrazek.png


Original Comments

Feedback Bot on 3/24/2025, 09:08 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Feedback Bot on 3/26/2025, 11:42 AM:

This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.

<agent_instructions>@copilot in the "AwaitCompletionProvider" see if we're inside a private method that is also being used to hookup an event somewhere in the containing type. If so, don't change the return type to be 'Task'.</agent_instructions>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix C# editor breaking change with await in event handler Fix await completion changing void to Task for event handler methods Nov 19, 2025
Copilot AI requested a review from CyrusNajmabadi November 19, 2025 22:20
Copilot finished work on behalf of CyrusNajmabadi November 19, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C# editor breaking change in behavior when writing await keyword inside event handler

2 participants