{"record":{"id":"db893f1c853cef9d","repo":"dotnet/wpf","slug":"sr-format-sr-mustbeoftype-value-resourcereferenceexpression","errorCode":null,"errorMessage":"SR.Format(SR.MustBeOfType, \"value\", \"ResourceReferenceExpression\")","messagePattern":"SR\\.Format\\(SR\\.MustBeOfType, \"value\", \"ResourceReferenceExpression\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceReferenceExpressionConverter.cs","lineNumber":116,"sourceCode":"        /// <param name=\"culture\">\n        ///     current culture (see CLR specs)\n        /// </param>\n        /// <param name=\"value\">\n        ///     value to convert from\n        /// </param>\n        /// <param name=\"destinationType\">\n        ///     Type to convert to\n        /// </param>\n        /// <returns>\n        ///     converted value\n        /// </returns>\n        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n        {\n            // Validate Input Arguments\n            ResourceReferenceExpression expr = value as ResourceReferenceExpression;\n            if (expr == null)\n            {\n                throw new ArgumentException(SR.Format(SR.MustBeOfType, \"value\", \"ResourceReferenceExpression\"));\n            }\n            ArgumentNullException.ThrowIfNull(destinationType);\n\n            // MarkupExtension\n            if (destinationType == typeof(MarkupExtension))\n            {\n                return new DynamicResourceExtension(expr.ResourceKey);\n            }\n\n            return base.ConvertTo(context, culture, value, destinationType);\n        }\n    }\n}\n\n","sourceCodeStart":98,"sourceCodeEnd":131,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceReferenceExpressionConverter.cs#L98-L131","documentation":"Thrown as ArgumentException from ResourceReferenceExpressionConverter.ConvertTo when the 'value' argument is not a ResourceReferenceExpression. The converter only knows how to convert that specific expression type to MarkupExtension or InstanceDescriptor.","triggerScenarios":"Calling ConvertTo with a value that is null or a different Expression/MarkupExtension type; type converters invoked reflectively (e.g. designer serialization, XAML writer) over a mixed expression collection.","commonSituations":"Design-time tooling or XAML serialization walking properties whose value is not a resource reference; custom converters passing the wrong object.","solutions":["Check `value is ResourceReferenceExpression` before calling ConvertTo","Use the correct converter type for the expression you actually have","Filter collections to only ResourceReferenceExpression items before conversion"],"exampleFix":"// before\nconverter.ConvertTo(null, culture, someOtherExpression, typeof(MarkupExtension));\n// after\nif (value is ResourceReferenceExpression expr)\n    converter.ConvertTo(null, culture, expr, typeof(MarkupExtension));","handlingStrategy":"type-guard","validationCode":"if (!(value is ResourceReferenceExpression)) throw new ArgumentException(\"value must be a ResourceReferenceExpression\");","typeGuard":"bool IsResourceRef(object v) => v is ResourceReferenceExpression;","tryCatchPattern":"try { result = converter.ConvertTo(ctx, culture, value, destType); } catch (ArgumentException) { /* value was not a ResourceReferenceExpression */ }","preventionTips":["Match converter type to expression type","Filter expression collections before conversion"],"tags":["wpf","converter","type-mismatch","expression"],"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"}