CommunityToolkit / CommunityToolkit/dotnet

Can't compile under linux_x86_64 with dynamic type in ObservableProperty

Open
#876 2 comments 1 reaction 0 assignees View on GitHub
bug :bug:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### 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:

```csharp
[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:

```log
/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

```text
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.