Skip to content

Cannot create custom Dictionary in XAML #13373

@kazo0

Description

@kazo0

Current behavior

Code generation fails when attempting to instantiate a custom Dictionary class in XAML

Expected behavior

Code should generate fine

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

Create a custom Dictionary class such as

public class MyDictionary : Dictionary<string, string> { }

Attempt to create a instance of MyDictionary in your XAML

<Page.Resources>
	<local:MyDictionary x:Key="MyDict">
		<x:String x:Key="One">One</x:String>
		<x:String x:Key="Two">Two</x:String>
	</local:MyDictionary>
</Page.Resources>

Note the build error:

error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'Dictionary<string, string>.Add(string, string)'

Sample repro app attached. Just remove the win: prefix in the Page.Resources of the MainPage.xaml to see the error
UnoApp57.zip

Workaround

No response

Works on UWP/WinUI

Yes

Environment

No response

NuGet package version(s)

No response

Affected platforms

Build tasks

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/code-generationCategorizes an issue or PR as relevant to code generationdifficulty/medium 🤔Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUIhas-repro-branchkind/bugSomething isn't workingtriage/potentially-fixedCategorizes an issue as potentially fixed by some unlinked PR, fix needs to be verified

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions