dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Can't compile under linux_x86_64 with dynamic type in ObservableProperty

Open jindongjie opened this issue 9 months ago • 2 comments

Describe the bug

I'm trying to compile a C# Avalonia crossplatform project on Linux that uses the MVVM Community Toolkit. The project compiles and runs fine on Windows, but on Linux I'm getting a compilation error with the following line of code:

[ObservableProperty]
private dynamic _selectedDevice = null!;

The program compiles without errors on Windows, even when I target Linux as the runtime. However, when I transfer the compiled program to a Linux machine and try to run it, it fails with the following error:

/home/admin/Desktop/code/BTS/CommunityToolkit.Mvvm.SourceGenerators/CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator/WD_BTS.ViewModels.MainWindowViewModel.g.cs(63,46): error CS8716: There is no target type for the default literal.
/home/admin/Desktop/code/BTS/CommunityToolkit.Mvvm.SourceGenerators/CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator/WD_BTS.ViewModels.MainWindowViewModel.g.cs(67,45): error CS8716: There is no target type for the default literal.

Regression

8.2.2

Steps to reproduce

1. Make sure you are in a Linux environment.
2. Create a new cross-platform project using Avalonia. Make sure to select the Community Toolkit for MVVM during the setup.
3. Create a new View and ViewModel.
4. In the ViewModel, try to write the following code: 
[ObservableProperty]
private dynamic _selectedDevice = null!

Expected behavior

Code work fine :)

Screenshots

No response

IDE and version

Rider

IDE version

No response

Nuget packages

  • [ ] CommunityToolkit.Common
  • [ ] CommunityToolkit.Diagnostics
  • [ ] CommunityToolkit.HighPerformance
  • [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

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

jindongjie avatar May 13 '24 00:05 jindongjie