{"record":{"id":"c142cd0b56f1ed4d","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-loadertype","errorCode":null,"errorMessage":"ArgumentNullException(nameof(loaderType))","messagePattern":"ArgumentNullException\\(nameof\\(loaderType\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XamlDeferLoadAttribute.cs","lineNumber":21,"sourceCode":"\nnamespace System.Windows.Markup\n{\n    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]\n    public sealed class XamlDeferLoadAttribute : Attribute\n    {\n        public XamlDeferLoadAttribute(Type loaderType, Type contentType)\n        {\n            ArgumentNullException.ThrowIfNull(loaderType);\n            ArgumentNullException.ThrowIfNull(contentType);\n            LoaderTypeName = loaderType.AssemblyQualifiedName!;\n            ContentTypeName = contentType.AssemblyQualifiedName!;\n            LoaderType = loaderType;\n            ContentType = contentType;\n        }\n\n        public XamlDeferLoadAttribute(string loaderType, string contentType)\n        {\n            LoaderTypeName = loaderType ?? throw new ArgumentNullException(nameof(loaderType));\n            ContentTypeName = contentType ?? throw new ArgumentNullException(nameof(contentType));\n        }\n\n        public string LoaderTypeName { get; }\n\n        public string ContentTypeName { get; }\n\n        public Type? LoaderType { get; private set; }\n        public Type? ContentType { get; private set; }\n    }\n}\n","sourceCodeStart":3,"sourceCodeEnd":33,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XamlDeferLoadAttribute.cs#L3-L33","documentation":"The XamlDeferLoadAttribute(string,string) constructor throws ArgumentNullException when the loaderType string is null. This attribute records deferred-loading type names as strings for the XAML parser; a null loader name is meaningless and rejected at construction.","triggerScenarios":"Executing new XamlDeferLoadAttribute(null, \"SomeContentType\") or new XamlDeferLoadAttribute(null, null).","commonSituations":"Building the attribute via reflection/config-driven code where the loader type name comes from a missing setting; hand-writing attribute metadata and leaving the loader argument empty.","solutions":["Pass a valid assembly-qualified or XAML-namespace type-name string for loaderType.","Validate the config/source value for null before constructing the attribute.","Use the (Type,Type) constructor overload with concrete types when available.","Catch ArgumentNullException and log/skip invalid attribute metadata."],"exampleFix":"// before\nvar attr = new XamlDeferLoadAttribute(GetSetting(\"loader\"), \"MyContent\"); // setting missing\n// after\nvar loader = GetSetting(\"loader\") ?? \"MyNs.MyDeferredLoader\";\nvar attr = new XamlDeferLoadAttribute(loader, \"MyContent\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(loaderTypeName)) throw new ArgumentException(\"loaderType is required.\");\nvar attr = new XamlDeferLoadAttribute(loaderTypeName, contentTypeName);","typeGuard":null,"tryCatchPattern":"try { attr = new XamlDeferLoadAttribute(loader, content); }\ncatch (ArgumentNullException ex) { log.Error($\"Bad defer-load metadata: {ex.ParamName}\"); attr = null; }","preventionTips":["Prefer the (Type, Type) constructor overload so the compiler catches missing values.","Validate configuration values before building attributes from them."],"tags":["xaml","wpf","null-argument","attribute","constructor"],"backgroundTag":"null-argument","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"}