{"record":{"id":"8bb84566a74ca55b","repo":"dotnet/wpf","slug":"sr-format-sr-mustbeoftype-nameof-value-nameof","errorCode":null,"errorMessage":"SR.Format(SR.MustBeOfType, nameof(value), nameof(StaticExtension))","messagePattern":"SR\\.Format\\(SR\\.MustBeOfType, nameof\\(value\\), nameof\\(StaticExtension\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtensionsToInstanceDescriptorsConverter.cs","lineNumber":32,"sourceCode":"#pragma warning restore CA1812\n    {\n        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)\n        {\n            if (destinationType == typeof(InstanceDescriptor))\n            {\n                return true;\n            }\n\n            return base.CanConvertTo(context, destinationType);\n        }\n\n        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n        {\n            if (destinationType == typeof(InstanceDescriptor))\n            {\n                if (!(value is StaticExtension staticExtension))\n                {\n                    throw new ArgumentException(SR.Format(SR.MustBeOfType, nameof(value), nameof(StaticExtension)));\n                }\n\n                return new InstanceDescriptor(\n                    typeof(StaticExtension).GetConstructor(new Type[] { typeof(string) }),\n                    new object[] { staticExtension.Member }\n                );\n            }\n\n            return base.ConvertTo(context, culture, value, destinationType);\n        }\n    }\n}\n","sourceCodeStart":14,"sourceCodeEnd":45,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtensionsToInstanceDescriptorsConverter.cs#L14-L45","documentation":"StaticExtensionsToInstanceDescriptorsConverter.ConvertTo only converts a StaticExtension value into an InstanceDescriptor. If the value passed to ConvertTo is not a StaticExtension, it throws ArgumentException(SR.MustBeOfType), reporting the value parameter must be of type StaticExtension.","triggerScenarios":"Calling converter.ConvertTo(context, culture, someOtherObject, typeof(InstanceDescriptor)) with a value that is not StaticExtension — e.g. a TypeExtension or a raw string.","commonSituations":"Custom designer/serializer pipelines that feed mixed markup-extension values into the converter; code that assumes the converter accepts any markup extension.","solutions":["Pass only StaticExtension instances to this converter.","Type-check (value is StaticExtension) before invoking ConvertTo.","Use the converter registered for the actual value's type instead."],"exampleFix":"// before\nvar descriptor = converter.ConvertTo(null, culture, typeExtension, typeof(InstanceDescriptor));\n// after\nif (value is StaticExtension staticExtension)\n    var descriptor = converter.ConvertTo(null, culture, staticExtension, typeof(InstanceDescriptor));","handlingStrategy":"type-guard","validationCode":"if (value is not StaticExtension) throw new ArgumentException($\"ConvertTo(InstanceDescriptor) requires a StaticExtension, got {value?.GetType().Name ?? \"null\"}\");","typeGuard":"static bool IsStaticExtension(object? v) => v is StaticExtension;","tryCatchPattern":"try { result = converter.ConvertTo(ctx, culture, value, typeof(InstanceDescriptor)); } catch (ArgumentException ex) { /* wrong value type for this converter */ }","preventionTips":["Check value.GetType() before dispatching to a type-specific converter.","Route each value to the converter registered for its own type."],"tags":["xaml","converter","type-mismatch","argumentexception"],"backgroundTag":"type-mismatch","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"}