{"record":{"id":"5747df3a6d0d7bf0","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-contenttype","errorCode":null,"errorMessage":"ArgumentNullException(nameof(contentType))","messagePattern":"ArgumentNullException\\(nameof\\(contentType\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XamlDeferLoadAttribute.cs","lineNumber":22,"sourceCode":"namespace 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":4,"sourceCodeEnd":33,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XamlDeferLoadAttribute.cs#L4-L33","documentation":"The XamlDeferLoadAttribute(string,string) constructor throws ArgumentNullException when the contentType string is null. Alongside the loader type name, the content type name is required metadata for deferred XAML loading, so null is rejected immediately.","triggerScenarios":"Executing new XamlDeferLoadAttribute(\"MyLoader\", null) or new XamlDeferLoadAttribute(null, null).","commonSituations":"Config-driven attribute construction where the content-type setting is absent; hand-authoring attribute metadata with a placeholder never filled in.","solutions":["Pass a valid type-name string for contentType.","Validate the source value for null before constructing.","Use the (Type,Type) constructor overload with concrete types.","Catch ArgumentNullException around attribute construction when inputs are untrusted."],"exampleFix":"// before\nvar attr = new XamlDeferLoadAttribute(\"MyLoader\", GetSetting(\"content\")); // null\n// after\nvar content = GetSetting(\"content\") ?? \"MyNs.MyContent\";\nvar attr = new XamlDeferLoadAttribute(\"MyLoader\", content);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(contentTypeName)) throw new ArgumentException(\"contentType 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 with concrete types.","Validate all attribute inputs sourced from config before construction."],"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"}