dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Observable Property Generator Errors

Open QJS-RH opened this issue 1 year ago • 9 comments

NEW WPF Application. Add Community.Toolkit.Mvvm V8.0.0 Add MainWindowVM class as

`public partial class MainWindowVM : ObservableObject { public MainWindowVM() { ApplicationName = "RHOKS Automation"; }

    private string? m_ApplicationName;
    public string? ApplicationName
    {
        get => m_ApplicationName;
        set => SetProperty(ref m_ApplicationName, value);
    }

    //[ObservableProperty]
    //private string? m_ApplicationName;

}`

Build works OK.

Change Class to

`public partial class MainWindowVM : ObservableObject { public MainWindowVM() { ApplicationName = "RHOKS Automation"; }

        [ObservableProperty]
        private string? m_ApplicationName;

    }`
17Errors

17 Errors Appear

Just upgraded to VS 17.3.2 VS Pro 2022 64-bit

QJS-RH avatar Aug 29 '22 23:08 QJS-RH

I haven't updated yet (VS 17.3.0) and I have the exact same issue with the simplest of projects. My project is .net 6.

` public partial class MainWindowViewModel : ObservableObject { [ObservableProperty] [NotifyPropertyChangedFor(nameof(ExpandedWidth))] private bool isExpanded;

    public GridLength ExpandedWidth
    {
        get
        {
            if (IsExpanded)
                return new GridLength(1, GridUnitType.Star);
            return new GridLength(0);
        }
    }
}

`

image

FormatException avatar Aug 31 '22 21:08 FormatException

This is all likely a dupe of #343

FormatException avatar Aug 31 '22 21:08 FormatException

which .net version is working for those Attributes used as generator? i create a viewmodel and mark a method with [RelayCommand]

  • when i use .net 6(lastest vs2022 preview), it says that there is "CS0102: xxxxx already contains a definition xxxxx"
  • when i switch to .net framework 4.7.2, it seems that there is nothing generated.

qycyfjy avatar Sep 01 '22 16:09 qycyfjy

which .net version is working for those Attributes used as generator? i create a viewmodel and mark a method with [RelayCommand]

  • when i use .net 6(lastest vs2022 preview), it says that there is "CS0102: xxxxx already contains a definition xxxxx"
  • when i switch to .net framework 4.7.2, it seems that there is nothing generated.

I never could get it to generate right with .net framework. I was trying with .net framework 4.8. I switched to .net 6 and only then would it generate.

FormatException avatar Sep 01 '22 17:09 FormatException

图片

Yes, switched to .net 6, it works, and.......works again. But I didn't find where the other definition is.

qycyfjy avatar Sep 01 '22 17:09 qycyfjy

If this is in a WPF app, you can try moving the view model to a separate class project or follow this workaround.

MisinformedDNA avatar Sep 02 '22 16:09 MisinformedDNA

Has there been any resolution for this issue yet? I am seeing this with v8.0.0, .NET 6 and VS 2022. I haven't tried all the suggested workarounds yet but the few I did try did not help.

jkrusso avatar Sep 13 '22 17:09 jkrusso

I think the official fix isn't out just yet. @jkrusso have you tried this one? It should fix it: https://github.com/dotnet/wpf/issues/6792#issuecomment-1183633402.

Sergio0694 avatar Sep 13 '22 17:09 Sergio0694

@Sergio0694 Yes, that workaround seems to work. Thanks

jkrusso avatar Sep 13 '22 20:09 jkrusso