Skip to content

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

Open
@morning4coffe-dev

Description

@morning4coffe-dev

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)

Metadata

Metadata

Assignees

Labels

area/code-generationCategorizes an issue or PR as relevant to code generationdifficulty/tbdCategorizes an issue for which the difficulty level needs to be defined.kind/bugSomething isn't workingtriage/untriagedIndicates an issue requires triaging or verification

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions