{"record":{"id":"48f67fe5e539bf53","repo":"unoplatform/uno","slug":"context","errorCode":null,"errorMessage":"context","messagePattern":"context","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Windows.Markup/NameReferenceConverter.cs","lineNumber":54,"sourceCode":"\t\t\treturn sourceType == typeof (string);\n\t\t}\n\n\t\tpublic override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)\n\t\t{\n\t\t\tif (context == null)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tvar p = context.GetService (typeof (IXamlNameProvider)) as IXamlNameProvider;\n\t\t\treturn p != null && destinationType == typeof (string);\n\t\t}\n\n\t\tpublic override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)\n\t\t{\n\t\t\tif (context == null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentNullException (\"context\");\n\t\t\t}\n\n\t\t\tvar s = value as string;\n\t\t\tif (String.IsNullOrEmpty (s))\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException (\"Value must be non-null string.\");\n\t\t\t}\n\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n\t\t{\n\t\t\tif (context == null)\n\t\t\t{\n\t\t\t\treturn null;\n\t\t\t}\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Windows.Markup/NameReferenceConverter.cs#L36-L72","documentation":"ArgumentNullException thrown by NameReferenceConverter.ConvertFrom (System.Xaml, ported from Mono) when the ITypeDescriptorContext argument is null. The converter needs the context to obtain IXamlNameProvider and to decide convertibility, so a null context is rejected with parameter name 'context'.","triggerScenarios":"Calling ConvertFrom(null, culture, value) directly — outside a designer/type-descriptor pipeline that normally provides the context.","commonSituations":"Programmatic conversion in tests or custom hosting that omits the descriptor context, or a code path that drops the context before invoking the converter.","solutions":["Pass a non-null ITypeDescriptorContext obtained from the type-descriptor pipeline.","In tests, build a minimal context whose GetService returns IXamlNameProvider.","Null-check at the call site and supply a real context before converting."],"exampleFix":"// before\nvar s = (string)converter.ConvertFrom(null, CultureInfo.InvariantCulture, \"Foo\");\n\n// after\nvar s = (string)converter.ConvertFrom(descriptorContext, CultureInfo.InvariantCulture, \"Foo\");","handlingStrategy":"validation","validationCode":"static string Convert(NameReferenceConverter c, ITypeDescriptorContext ctx, string value) { if (ctx is null) throw new ArgumentNullException(nameof(ctx)); return (string)c.ConvertFrom(ctx, CultureInfo.InvariantCulture, value); }","typeGuard":"static bool HasContext(ITypeDescriptorContext ctx) => ctx?.GetService(typeof(IXamlNameProvider)) is not null;","tryCatchPattern":"try { return (string)converter.ConvertFrom(ctx, culture, value); } catch (ArgumentNullException ex) when (ex.ParamName == \"context\") { throw new InvalidOperationException(\"NameReferenceConverter requires a type-descriptor context.\"); }","preventionTips":["Always pass the type-descriptor context from the designer pipeline.","In tests, build a context whose GetService returns IXamlNameProvider.","Null-check the context before invoking the converter."],"tags":["xaml","type-converter","namereference","argumentnull","system-xaml"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}