dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.07k stars 4.04k forks source link

Unhelpful error from event hookup #7565

Closed rchande closed 12 months ago

rchande commented 8 years ago

Try to use event hookup on tab at the caret. If you typo-ed your event declaration like I did, you get an error about "couldn't create solution". Perhaps we could

  1. Fail, but indicate why it failed
  2. Generate an eventhandler with a bad signature (you get the same error if the type doesn't exist, so this might be useful for GFU scenarios).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

class Eventer
{
    public event EventArgs e;
}

class Program
{
    Eventer e = new Eventer();
    void Main(string[] args)
    {
        this.e.e +=$$
    }

}

image

dpoeschl commented 8 years ago

The failure is happening here: http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp.EditorFeatures/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs,256

We could definitely give a better error message here, but using System.EventHandler when the delegate type can't be inferred would be fine too.

CyrusNajmabadi commented 12 months ago

Closing out as not-repro. We don't give any error now. The experience seems fine to me. THe code is in error and doesn't generate anything.