unoplatform/uno · error · XamlGenerationException
Local values are not allowed in resource dictionary with Sou
Error message
Local values are not allowed in resource dictionary with Source set
What it means
Thrown in the dictionary-building loop when a ResourceDictionary entry has both a Source member and _UnknownContent (i.e. local inline entries) set. WinUI/Uno semantics: a ResourceDictionary that references an external Source file cannot also contain locally-defined entries in the same element. The two are mutually exclusive because the Source fully defines the dictionary contents.
Source
Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:3046
return;
}
if (isInInitializer)
{
writer.AppendLineInvariantIndented("{0} = {{", propertyName);
}
else
{
writer.AppendLineInvariantIndented("// {0}", propertyName);
}
for (int i = 0; i < dictionaries.Objects.Count; i++)
{
var dictObject = dictionaries.Objects[i];
var source = dictObject.Members.FirstOrDefault(m => m.Member.Name == "Source");
if (source != null && dictObject.Members.Any(m => m.Member.Name == "_UnknownContent"))
{
throw new XamlGenerationException("Local values are not allowed in resource dictionary with Source set", dictObject);
}
var key = GetDictionaryResourceKey(dictObject);
if (isDict && key == null)
{
throw new XamlGenerationException("Each dictionary entry must have a 'Key'", dictObject);
}
var former = _themeDictionaryCurrentlyBuilding; //Will 99% of the time be null.
if (isDict)
{
_themeDictionaryCurrentlyBuilding = key;
}
if (!isSetExtensionMethod)
{
if (!isInInitializer && !isDict)
{View on GitHub (pinned to 0418340488)
Solutions
- Split into two elements: one <ResourceDictionary Source="..."/> inside <MergedDictionaries>, and a sibling for local entries at the parent level.
- Move local resources into the parent ResourceDictionary (not inside the Source-referenced one).
- If you only need the external dictionary, remove the inline entries.
Example fix
<!-- before -->
<ResourceDictionary Source="ms-appx:///Shared.xaml">
<SolidColorBrush x:Key="Local" Color="Red"/>
</ResourceDictionary>
<!-- after -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Shared.xaml"/>
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="Local" Color="Red"/>
</ResourceDictionary> Defensive patterns
Strategy: validation
Validate before calling
# Flag <ResourceDictionary Source="..."> that also contains child elements
Get-ChildItem -Recurse -Filter *.xaml | ForEach-Object {
$text = Get-Content $_.FullName -Raw
[regex]::Matches($text, '<ResourceDictionary\s+[^>]*Source="[^"]+"[^>]*>(.*?)</ResourceDirectory>', 'Singleline') |
ForEach-Object { if ($_.Groups[1].Value -match '<') { Write-Warning "ResourceDictionary with Source has local content" } }
} Prevention
- Remember: a Source-referenced ResourceDictionary is a leaf — put local resources in the parent dictionary.
- Use the MergedDictionaries pattern: parent ResourceDictionary > .MergedDictionaries > child Source dictionaries.
When it happens
Trigger: Writing <ResourceDictionary Source="..."> with child <Style>/<Brush> entries directly inside the same element; combining MergedDictionaries Source references with inline resources at the wrong nesting level.
Common situations: Attempting to add a local override alongside a merged dictionary in the same tag; misunderstanding that Source and local content must be in separate ResourceDictionary elements.
Related errors
- '{memberName}' is not defined on '{xamlObjectDefinition.Type
- There is already a resource with name '{name}'
- Each dictionary entry must have a 'Key'
- Unable to find the type {typeName} in key {resource.Key}
- Dictionary item '{resource.Type?.Name}' has duplicate key '{
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/3b86197047e78a80.
Report an issue: GitHub.