Skip to content

Duplicating a method with the ICommand attribute breaks source generator #154

Closed

Description

@powerdude

Not sure if it's a bigger VS problem or not, but it's a bit disruptive. Add the following to a view model:

[ICommand]
private void DoSomething()
{
}

Now, highlight all three lines and press Ctrl-D (or copy and paste) at least 3 times. The ICommandSourceGenerator breaks, the previously generated files disappear and even after adding a unique suffix to each method, it won't create any new files. The same thing doesn't happen with:

[ObservableProperty] int foo;

Activity

  1. self-assigned this
    on Mar 15, 2022
  2. added
    bug 🐛An unexpected issue that highlights incorrect behavior
    next preview ✈️This changes will be available in the upcoming preview
    priority 🚩An issue or change that has priority
    on Mar 15, 2022
  3. Sergio0694 commented on Mar 15, 2022

    @Sergio0694
    Member

    Hey @powerdude, thank you for reporting this!
    I can repro this, the issue is a name collision in the name hints for the generated files. This only happens with the [ICommand] generator because it's emitting one file per command, whereas [ObservableProperty] combines all generated properties into the same file. I'll make a PR to fix this 🙂

  4. Sergio0694 commented on Mar 16, 2022

    @Sergio0694
    Member

    So, this is also related to dotnet/roslyn#58625, so it needs to be fixed in VS/Roslyn.
    That said, I can also add explicit diagnostics for [ICommand] though, with a clearer error message.
    This might especially help in cases where people try to use [ICommand] on multiple overloads of a method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛An unexpected issue that highlights incorrect behaviormvvm-toolkit 🧰Issues/PRs for the MVVM Toolkitnext preview ✈️This changes will be available in the upcoming previewpriority 🚩An issue or change that has priority

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions