dotnet
dotnet copied to clipboard
Observable Property Generator Errors
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;
}`
17 Errors Appear
Just upgraded to VS 17.3.2 VS Pro 2022 64-bit
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);
}
}
}
`
This is all likely a dupe of #343
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.
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.
Yes, switched to .net 6, it works, and.......works again. But I didn't find where the other definition is.
If this is in a WPF app, you can try moving the view model to a separate class project or follow this workaround.
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.
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 Yes, that workaround seems to work. Thanks