dotnet/wpf · error · XamlObjectWriterException
SR.LineNumberOnly (accumulated name-fixup error message)
Error message
SR.LineNumberOnly (accumulated name-fixup error message)
What it means
XamlObjectWriterException raised with an accumulated message of name-fixup failures: after loading, every x:Name/registered name that failed to resolve to its backing CLR member or field is appended (with line numbers via SR.LineNumberOnly) and all failures are thrown together. It signals that names declared in XAML could not be attached to the generated/assigned object graph.
Solutions
- Rebuild the project so the generated .g.cs/.i.g.cs name fields match the current XAML x:Name declarations.
- Remove or rename duplicate x:Name values within the same namescope.
- Ensure every x:Name has a matching field/property in the code-behind type (or drop the x:Name).
- Read the accumulated message's line numbers — each SR.LineNumberOnly entry points at the offending XAML line.
Example fix
// before (XAML) <Button x:Name="oldButtonName" ... /> <!-- no matching field in code-behind --> // after <Button x:Name="submitButton" ... /> <!-- matches generated field, or remove x:Name -->
Defensive patterns
Strategy: try-catch
Validate before calling
// before load: verify each x:Name has a matching member on the root/code-behind type
foreach (var name in xamlNames)
if (rootType.GetField(name) == null && rootType.GetProperty(name) == null)
throw new InvalidOperationException($"x:Name '{name}' has no matching member."); Try / catch
try { writer.Close(); }
catch (XamlObjectWriterException ex)
{
foreach (Match m in Regex.Matches(ex.Message, @"line (\d+)"))
ReportNameError(int.Parse(m.Groups[1].Value));
} Prevention
- Rebuild after editing XAML so generated name fields stay in sync.
- Keep x:Name values unique within each namescope.
- Remove x:Name from elements not referenced in code-behind.
- Parse the accumulated message's line numbers to locate every offender at once.
When it happens
Trigger: End-of-load name fixup in XamlObjectWriter encounters names registered via x:Name (or Name property) that have no corresponding field/property to store the instance into, or duplicate names in the stream; failures accumulate across the whole document and are thrown as one exception.
Common situations: x:Name referencing fields removed or renamed in code-behind/partial classes; duplicate x:Name values within one namescope; XAML compiled against an older generated .g.cs than the runtime types (stale build artifacts); shared resources causing namescope collisions.
Related errors
- Storyboard_NameNotFound
- SR.Format(SR.CannotHavePropertyInTemplate…
- SR.Format(SR.NameNotFound, propertyValue.ChildName)
- SR.Format(SR.NameScopeDuplicateNamesNotAllowed, childName)
- SR.Format(SR.NameScopeNotFound, name, "register")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/457e70d1ff4528ed.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs:2390
{
exceptionMessage.AppendLine();
}
exceptionMessage.Append(SR.Format(SR.UnresolvedForwardReferences, token.NeededNames[0]));
if (token.LineNumber != 0)
{
if (token.LinePosition != 0)
{
exceptionMessage.Append(SR.Format(SR.LineNumberAndPosition, string.Empty, token.LineNumber, token.LinePosition));
}
exceptionMessage.Append(SR.Format(SR.LineNumberOnly, string.Empty, token.LineNumber));
}
first = false;
}
throw new XamlObjectWriterException(exceptionMessage.ToString());
}
private void TriggerNameResolution(object instance, string name)
{
#if DEBUG
Debug.Assert(!_inNameResolution);
_inNameResolution = true;
#endif
Debug.Assert(_nameFixupGraph is not null);
_nameFixupGraph.ResolveDependenciesTo(instance, name);
while (_nameFixupGraph.HasResolvedTokensPendingProcessing)
{
NameFixupToken token = _nameFixupGraph.GetNextResolvedTokenPendingProcessing();
ProcessNameFixup(token, false);
// If this was a named type-converted object, and it's already off the stack, then
// it lost its chance to trigger name resolution in WriteEndObject. So resolve any
// dependencies to its name now.View on GitHub (pinned to 81131a70a4)