Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Generation fails when Items put directly inside List controls #18296

Open
morning4coffe-dev opened this issue Sep 25, 2024 · 2 comments
Open
Assignees
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification

Comments

@morning4coffe-dev
Copy link
Member

morning4coffe-dev commented Sep 25, 2024

Current behavior

When building the project on Uno targets it fails with:

error CS1527: Elements defined in a namespace cannot be explicitly declared as private, protected, protected internal, or private protected
A namespace cannot directly contain members such as fields, methods or statements
'IMainPage_Bindings' is inaccessible due to its protection level
The type '<invalid-global-code>' already contains a definition for '_Item'
The type '<invalid-global-code>' already contains a definition for 'Item'
IMainPage_Bindings' is inaccessible due to its protection level
IMainPage_Bindings' in explicit interface declaration is not an interface
The type 'MainPage' already contains a definition for '_Item'
...

This works well with WinUI.

Expected behavior

No response

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

e.g.

    <ListView ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
      <ListView.Items>
        <local:Item IsSpecial="False" />
        <local:Item IsSpecial="True" />
        <local:Item IsSpecial="False" />
        <local:Item IsSpecial="True" />
      </ListView.Items>
    </ListView>

more detailed repro:
SourceGenitemsIssue.zip

Workaround

Rename Item class to anything else.

    <ListView ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
      <ListView.Items>
        <local:MyEntity IsSpecial="False" />
        <local:MyEntity IsSpecial="True" />
        <local:MyEntity IsSpecial="False" />
        <local:MyEntity IsSpecial="True" />
      </ListView.Items>
    </ListView>

No response

Works on UWP/WinUI

Yes

Environment

No response

NuGet package version(s)

No response

Affected platforms

WebAssembly, Android, iOS, Mac Catalyst, Skia (WPF), Skia (Linux X11), Skia (macOS), Skia (Linux Framebuffer), Skia (GTK)

@morning4coffe-dev morning4coffe-dev added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Sep 25, 2024
@Youssef1313 Youssef1313 added the area/code-generation Categorizes an issue or PR as relevant to code generation label Sep 25, 2024
@jeromelaban
Copy link
Member

This is caused by the fact that the name of the class is called "Item". Try naming it differently as a workaround.

@morning4coffe-dev
Copy link
Member Author

@jeromelaban Jup, after renaming, I can confirm, that it works! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

3 participants