CommunityToolkit / CommunityToolkit/dotnet
.NET Framework (WPF) Source Generators not working (when in same project)
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 400
- PR merge metrics
- No merged PRs in 30d
Description
1.) Create a new WPF Framework app and flip on C# 10
2.) Create a simple view model:
```csharp
public partial class MainViewModel : ObservableObject
{
public MainViewModel()
{
}
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(FullName))]
string firstName;
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(FullName))]
string lastName;
public string FullName => $"{FirstName} {LastName}";
[ICommand]
async Task Submit()
{
Debug.WriteLine("DEBUG INFO: Submitted");
this.FirstName = "test";
}
}
```
The code will not compile and says that `FirstName` and `LastName` do not exist, even though there are no red squiggles and also the code is generated. The funny part is if you don't reference `FirstName` or `LastName` and only use `firstName` and `lastName` then the app will run and everything works...
Work around:
Create a .NET Standard 2.0 library, flip on C# 10, and then move the ViewModel over there and it will work great.
See: https://github.com/jamesmontemagno/MVVMSourceGenerators/ for reference
Contributor guide
Assessment
This issue has not been assessed yet.