CommunityToolkit / CommunityToolkit/Maui

[BUG] BindableProperty Color with DynamicResource and SourceGeneration throws errors on build

Open
#3,225 1 comment 0 reactions 0 assignees View on GitHub
bug unverified
Dominant language
C#
Stars
2.7k
Forks
500
Avg merge
2d 14h
Merged PRs (30d)
7

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Did you read the "Reporting a bug" section on Contributing file?

- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

### Current Behavior

When you create property:
```
[CommunityToolkit.Maui.BindableProperty]
public partial Color NotWorkingColor { get; set; }
```
and then try to bind to that property with a DynamicResource:
```
NotWorkingColor="{x:DynamicResource DummyColor}"
```

an error happens when building:
0>MainPage.xaml.xsg.cs(102,114): Error CS0030 : Cannot convert type 'Microsoft.Maui.Controls.Internals.DynamicResource' to 'Microsoft.Maui.Graphics.Color'

### Expected Behavior

The project builds and BindableProperty generated by the package works like manually created BindableProperty.

### Steps To Reproduce

Try to build project.

### Link to public reproduction project repository

https://github.com/Pastajello/CTM_BindableProperty_DynamicResource

### Environment

```markdown
- .NET MAUI CommunityToolkit: 14.1.1
- OS: MacOS 26.4.1.
- .NET MAUI: 10.0.70
```

### Anything else?

AutoBindable BindingProperty generator doesnt produce this issue:
https://github.com/rrmanzano/maui-bindableproperty-generator
but produces another with SourceGen :
An error occured while parsing Xaml: The given key 'Microsoft.Maui.Controls.Xaml.ValueNode' was not present in the dictionary

Contributor guide

Open the contributing guide

Research direction

Start with the public reproduction repository and the generated MainPage.xaml.xsg.cs location shown in the build error. Reproduce the build using the reported .NET MAUI CommunityToolkit version, then trace the BindableProperty source generator handling of DynamicResource and compare it with a manually created BindableProperty. Done means the reproduction builds and the generated property accepts the DynamicResource binding.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
mobile-dev, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.