{"record":{"id":"b77eb81cd573a5da","repo":"dotnet/wpf","slug":"sr-format-sr-typevalueserializerunavailable-this-gettype","errorCode":null,"errorMessage":"SR.Format(SR.TypeValueSerializerUnavailable, this.GetType().Name )","messagePattern":"SR\\.Format\\(SR\\.TypeValueSerializerUnavailable, this\\.GetType\\(\\)\\.Name \\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/Command/CommandValueSerializer.cs","lineNumber":82,"sourceCode":"                    // Known Commands, so write shorter version\n                    if (CommandConverter.IsKnownType(command.OwnerType))\n                    {\n                        return command.Name;\n                    }\n                    else\n                    {\n                        ValueSerializer typeSerializer = null;\n\n                        if (context == null)\n                        {\n                            throw new InvalidOperationException(SR.Format(SR.ValueSerializerContextUnavailable, this.GetType().Name ));\n                        }\n\n                        // Get the ValueSerializer for the System.Type type\n                        typeSerializer = context.GetValueSerializerFor(typeof(Type));\n                        if (typeSerializer == null)\n                        {\n                            throw new InvalidOperationException(SR.Format(SR.TypeValueSerializerUnavailable, this.GetType().Name ));\n                        }\n\n                        return $\"{typeSerializer.ConvertToString(command.OwnerType, context)}.{command.Name}Command\";\n                    }\n                }\n            }\n            else\n                return string.Empty;\n            \n            throw GetConvertToException(value, typeof(string));\n        }\n\n        public override IEnumerable<Type> TypeReferences(object value, IValueSerializerContext context)\n        {\n            if (value != null)\n            {\n                RoutedCommand command = value as RoutedCommand;\n                if (command != null)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/Command/CommandValueSerializer.cs#L64-L100","documentation":"After obtaining a context, ConvertToString asks it for the ValueSerializer of System.Type (context.GetValueSerializerFor(typeof(Type))). If the context supplies none, the command's OwnerType cannot be serialized as an xmlns-qualified class name, so InvalidOperationException (SR.TypeValueSerializerUnavailable) is thrown.","triggerScenarios":"ConvertToString called with a custom or minimal ITypeDescriptorContext implementation that returns null from GetValueSerializerFor(typeof(Type)).","commonSituations":"Rehosting WPF designer services with incomplete type-descriptor providers; using a hand-rolled context in tests or custom markup serializers that lacks the built-in Type value serializer.","solutions":["Use the standard WPF/XAML serialization context (e.g., from the designer's SerializerContext or values produced by XamlReader/Writer pipelines) which registers TypeValueSerializer.","Register/provide a Type ValueSerializer in your custom ITypeDescriptorContext (see TypeValueSerializer in PresentationFramework).","Fall back to manual formatting: $\"{ClrNamespace(command.OwnerType)}:{command.OwnerType.Name}.{command.Name}Command\" when no context-provided serializer exists."],"exampleFix":"// before\ntypeSerializer = context.GetValueSerializerFor(typeof(Type));\nreturn $\"{typeSerializer.ConvertToString(command.OwnerType, context)}.{command.Name}Command\";\n\n// after\nvar typeSerializer = context?.GetValueSerializerFor(typeof(Type));\nif (typeSerializer == null)\n    return $\"{command.OwnerType.FullName}.{command.Name}Command\"; // fallback\nreturn $\"{typeSerializer.ConvertToString(command.OwnerType, context)}.{command.Name}Command\";","handlingStrategy":"fallback","validationCode":"var typeSerializer = context?.GetValueSerializerFor(typeof(Type));\nif (typeSerializer == null)\n    return $\"{command.OwnerType.FullName}.{command.Name}Command\"; // fallback path","typeGuard":"bool HasTypeSerializer(ITypeDescriptorContext ctx) => ctx?.GetValueSerializerFor(typeof(Type)) != null;","tryCatchPattern":"try { s = serializer.ConvertToString(command, context); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ValueSerializer\"))\n{ s = $\"{command.OwnerType.FullName}.{command.Name}Command\"; }","preventionTips":["Use the standard WPF/XAML serialization context that registers the Type ValueSerializer.","Register a Type serializer in any custom ITypeDescriptorContext you implement.","Keep a manual ns:Class formatting fallback for non-XAML hosts."],"tags":["wpf","valueserializer","routedcommand","invalidoperationexception","type-serializer"],"backgroundTag":"missing-dependency","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}