Skip to content

x:Bind not support the property generated by source generator #14409

Open

Description

@SongOfYouth

Current behavior

I have generated the property via IIncrementalGenerator source generator like this:
image

and bind it in the xaml file:
image

then build, it comes out:

D:\Dysoft\Git\HIS3.0\Busi\Base\Dy.Base.UI\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\DictionaryTypePage_08d21259fdf0d2994045384693412e24.cs(111,407,111,605): error CS0029: Cannot implicitly convert type 'Dy.Base.UI.ViewModels.DictionaryTypeItemViewModel' to 'string'

Expected behavior

No response

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

Yes

Environment

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

What i have bound to the Text of TextBox is property Code, but the error points to the ViewModel type converting fail.

Activity

  1. added
    difficulty/tbd
    kind/bug
    triage/untriaged
    on Nov 14, 2023
  2. added
    area/code-generation
    area/xBind 🪢
    project/binding 🪢
    difficulty/medium 🤔
    and removed
    triage/untriaged
    difficulty/tbd
    on Nov 14, 2023
  3. jeromelaban commented on Nov 14, 2023

    @jeromelaban
    Member

    Thanks for the report. It seems that the code you're referencing is coming from a Source Generator. This is currently not supported because of #12073, which is ultimately caused by dotnet/roslyn#57239.

    If you need this to work, you'll need to place your ViewModel classes in a separate library project from the XAML files.

  4. SongOfYouth commented on Nov 15, 2023

    @SongOfYouth
    Author

    Thanks for the report. It seems that the code you're referencing is coming from a Source Generator. This is currently not supported because of #12073, which is ultimately caused by dotnet/roslyn#57239.

    If you need this to work, you'll need to place your ViewModel classes in a separate library project from the XAML files.

    I think so too.but problem is the same code which from mvvmtoolkit source generator works well...

    [ObeservaleProperty]
    string _code;
  5. jeromelaban commented on Nov 15, 2023

    @jeromelaban
    Member

    It works with MVVM Toolkit because Uno has a specific workaround for this library. It does not know about the other generators and can't generate code properly.

  6. Youssef1313 commented on Jun 12, 2024

    @Youssef1313
    Member

    Best that can be done here is separating out the ViewModels to a separate project, if possible.

    That way, the source generator will be run in the context of a project different than the one XAML generator runs in and things will work. I don't think this is currently fixable.

  7. Youssef1313 commented on Jun 12, 2024

    @Youssef1313
    Member

    Another possible workaround is also suggested in #12073 (comment)

  8. added theissue type on Jun 20, 2025
  9. github-actions commented on May 1, 2026

    @github-actions
    Contributor

    This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.

  10. added
    stale
    on May 1, 2026
  11. removed
    stale
    on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/code-generationarea/xBind 🪢difficulty/medium 🤔kind/bugproject/binding 🪢

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions