dotnet/wpf · error
(no message - parameterless InvalidOperationException)
Error message
(no message - parameterless InvalidOperationException)
What it means
MarkupWriter's internal value serializer converts a Type value to its XML namespace-qualified string form, but throws a parameterless InvalidOperationException when the value passed in is not a Type. This is an internal invariant violation: the serializer was invoked with a value it was never designed to handle.
Solutions
- Inspect the object being serialized and ensure every property that flows through the type serializer contains a non-null System.Type instance
- Check for nulls earlier in the object graph before calling MarkupWriter
- Wrap serialization in try/catch to log the offending property path
- If serializing custom types, register a proper value serializer that handles your value type
Example fix
// before
var markup = MarkupWriter.GetObjectMarkup(obj); // obj.SomeTypeProperty == null
// after
if (obj.SomeTypeProperty == null)
throw new InvalidOperationException("obj.SomeTypeProperty must be a Type before serialization");
var markup = MarkupWriter.GetObjectMarkup(obj); Defensive patterns
Strategy: validation
Validate before calling
if (value is not Type t || t == null)
throw new InvalidOperationException("Expected a System.Type value before MarkupWriter serialization"); Type guard
bool IsType(object v) => v is Type;
Try / catch
try { var markup = MarkupWriter.GetObjectMarkup(obj); }
catch (InvalidOperationException ex) { Log(ex); /* inspect obj graph for null/non-Type members */ } Prevention
- Ensure Type-typed properties are never null before serialization
- Unit-test serialization of your object graph
- Log property paths when serializing custom markup
When it happens
Trigger: Calling MarkupWriter/MarkupObject serialization APIs (e.g. MarkupWriter.GetObjectMarkup) or the XAML serializer pipeline where a member's value is null or not a System.Type when ConvertToString is dispatched for the x:Type-like value serializer.
Common situations: Serializing an object graph whose property typed/declared as Type is actually null or holds a non-Type instance; custom markup extensions or value serializer plumbing feeding unexpected values into the writer.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- ArgumentNullException(nameof(writer))
- SR.AddText_Invalid
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/10b628963d060115.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs:1526
private class TypeValueSerializer : ValueSerializer
{
private Scope _scope;
public TypeValueSerializer(Scope scope)
{
_scope = scope;
}
public override bool CanConvertToString(object value, IValueSerializerContext context)
{
return true;
}
public override string ConvertToString(object value, IValueSerializerContext context)
{
Type type = value as Type;
if (type == null)
throw new InvalidOperationException();
string uri = _scope.MakeAddressable(type);
string prefix = _scope.GetPrefixOf(uri);
if (prefix == null || prefix == "")
return type.Name;
else
return $"{prefix}:{type.Name}";
}
public override IEnumerable<Type> TypeReferences(object value, IValueSerializerContext context)
{
Type type = value as Type;
if (type != null)
return new Type[] { type };
else
return base.TypeReferences(value, context);
}
}
View on GitHub (pinned to 81131a70a4)