{"record":{"id":"04ad44a6983e57d9","repo":"dotnet/wpf","slug":"sr-format-sr-markupextensiontypenamebad-typename","errorCode":null,"errorMessage":"SR.Format(SR.MarkupExtensionTypeNameBad, _typeName)","messagePattern":"SR\\.Format\\(SR\\.MarkupExtensionTypeNameBad, _typeName\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs","lineNumber":78,"sourceCode":"            // Validate the initialization.\n            if (_typeName is null)\n            {\n                throw new InvalidOperationException(SR.MarkupExtensionTypeName);\n            }\n\n            // Get the IXamlTypeResolver from the service provider\n            ArgumentNullException.ThrowIfNull(serviceProvider);\n\n            if (serviceProvider.GetService(typeof(IXamlTypeResolver)) is not IXamlTypeResolver xamlTypeResolver)\n            {\n                throw new InvalidOperationException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, nameof(IXamlTypeResolver)));\n            }\n\n            // Get the type\n            _type = xamlTypeResolver.Resolve(_typeName);\n            if (_type is null)\n            {\n                throw new InvalidOperationException(SR.Format(SR.MarkupExtensionTypeNameBad, _typeName));\n            }\n\n            return _type;\n        }\n\n        /// <summary>\n        /// The typename represented by this markup extension. The name has the format\n        /// Prefix:Typename, where Prefix is the xml namespace prefix for this type.\n        /// </summary>\n        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\n        public string TypeName\n        {\n            get => _typeName;\n            set\n            {\n                // Reset the type so ProvideValue does not use the existing type.\n                _typeName = value ?? throw new ArgumentNullException(nameof(value));\n                _type = null;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs#L60-L96","documentation":"TypeExtension.ProvideValue throws InvalidOperationException when the IXamlTypeResolver.Resolve(_typeName) call returns null, i.e. the type-name string could not be resolved to any known type. The extension surfaces the offending _typeName in the message via SR.MarkupExtensionTypeNameBad.","triggerScenarios":"Setting TypeName to a string that the XAML type resolver cannot resolve — misspelled type name, missing xmlns prefix mapping, type not in referenced assemblies — then calling ProvideValue during a XAML parse.","commonSituations":"Typos in x:Type markup usage like {x:Type local:MyControll}; missing clr-namespace/xmlns declaration in the XAML file; renamed or moved type after a refactor; assembly not referenced by the project.","solutions":["Fix the TypeName string to match a resolvable type name, including the correct XML namespace prefix.","Add or correct the xmlns/clr-namespace mapping at the top of the XAML file.","Verify the type's assembly is referenced and the type is public.","Check for renames after refactoring and update the XAML reference."],"exampleFix":"// before\n<Window xmlns:local=\"clr-namespace:App.Views\">\n  <Button Tag=\"{x:Type local:MyControll}\" /> <!-- typo -->\n// after\n<Window xmlns:local=\"clr-namespace:App.Views\">\n  <Button Tag=\"{x:Type local:MyControl}\" />","handlingStrategy":"validation","validationCode":"// before writing {x:Type prefix:Name} in XAML, verify:\n// 1) xmlns:prefix mapping exists and points to the right clr-namespace/assembly\n// 2) the type name is spelled correctly and is public","typeGuard":null,"tryCatchPattern":"try { value = ext.ProvideValue(provider); }\ncatch (InvalidOperationException ex) { throw new XamlLoadException($\"Cannot resolve type '{ext.TypeName}'. Check xmlns mappings and assembly references.\", ex); }","preventionTips":["Compile-time check: reference types from code-behind to catch renames.","Keep clr-namespace mappings in one reviewed location.","Run XAML compilation (XamlC / BAML) in CI so unresolved types fail the build."],"tags":["xaml","wpf","type-resolution","markup-extension"],"backgroundTag":"resource-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}