CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.07k stars 299 forks source link

Ambiguous reference when using source generator #596

Closed yangbocheng closed 1 year ago

yangbocheng commented 1 year ago

Describe the bug

how to solve this problem? it seems has generated same properties

image

image

public partial class AllNoteViewModel : ObservableObject
{
    public AllNoteViewModel()
    {

        Notes = new ObservableCollection<NoteModel>();
        Notes.Add(new NoteModel
        {
            Text = "test1",
            Date = DateTime.Now.AddDays(1).ToString()
        });
        Notes.Add(new NoteModel
        {
            Text = "test2",
            Date = DateTime.Now.AddDays(2).ToString()
        });
    }

    public ObservableCollection<NoteModel> Notes { get; set; }

    [ObservableProperty]
    private string more;

}
public partial class NoteModel : ObservableObject
{
    [ObservableProperty]
    private string text;

    [ObservableProperty]
    private string date;

}

Regression

No response

Steps to reproduce

above all

Expected behavior

above all

Screenshots

No response

IDE and version

VS 2022 Preview

IDE version

17.5.0 Preview 5.0

Nuget packages

Nuget package version(s)

8.1.0

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

pijnappel commented 1 year ago

Can confirm. This is really annoying. This happens in my .NET MAUI project when targeting Windows and Android. The project builds successfully but the ViewModels are plastered with IntelliSense 'Ambiguous reference' Errors 'Ambiguous reference'.

ckrutsinger commented 1 year ago

I have seen this issue pop up from time to time. I have been able to clear it by closing and restarting VS.

Sergio0694 commented 1 year ago

This seems weird and potentially related to Roslyn. @yangbocheng do you repro in a blank .NET project? What is your setup, is that a multi-targeted project using some framework (eg. MAUI), or something else? I cannot repro in a blank .NET 6 project.

yangbocheng commented 1 year ago

This mistake happens too often。that's a maui,which install packages :communitytoolkit mvvm and maui, i have no way to offer an repo to show those mistakes, because, when reopen VS , or just a random minutes, those mistakes may or not may disappear

But it comes up a lot,just write some codes , write some properties, and complier, and debug and then continue . maybe then it must occurs