{"record":{"id":"dd74e35b81992965","repo":"dotnet/wpf","slug":"nameof-declaringtype","errorCode":null,"errorMessage":"nameof(declaringType)","messagePattern":"nameof\\(declaringType\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs","lineNumber":37,"sourceCode":"        private string _name;\n        private XamlType _declaringType;\n        private readonly MemberType _memberType;\n\n        // Idempotent\n        private ThreeValuedBool _isNameValid;\n\n        // Thread safety: if setting outside ctor, do an interlocked compare against null\n        private MemberReflector _reflector;\n\n        /// <summary>\n        /// Lazy init: NullableReference.IsSet is null when not initialized\n        /// </summary>\n        private NullableReference<MemberInfo> _underlyingMember;\n\n        public XamlMember(string name, XamlType declaringType, bool isAttachable)\n        {\n            _name = name ?? throw new ArgumentNullException(nameof(name));\n            _declaringType = declaringType ?? throw new ArgumentNullException(nameof(declaringType));\n            _memberType = isAttachable ? MemberType.Attachable : MemberType.Instance;\n        }\n\n        // Known property\n        public XamlMember(PropertyInfo propertyInfo, XamlSchemaContext schemaContext)\n            :this(propertyInfo, schemaContext, null)\n        {\n        }\n\n        public XamlMember(PropertyInfo propertyInfo, XamlSchemaContext schemaContext, XamlMemberInvoker invoker)\n            : this(propertyInfo, schemaContext, invoker, new MemberReflector(isEvent: false))\n        {\n        }\n\n        internal XamlMember(PropertyInfo propertyInfo, XamlSchemaContext schemaContext, XamlMemberInvoker invoker, MemberReflector reflector)\n        {\n            ArgumentNullException.ThrowIfNull(propertyInfo);\n            ArgumentNullException.ThrowIfNull(schemaContext);","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs#L19-L55","documentation":"XamlMember's constructor throws ArgumentNullException when the 'declaringType' argument is null. Every XamlMember must be associated with a XamlType that owns the member; without it the member cannot be resolved in a schema context.","triggerScenarios":"Calling new XamlMember(string name, XamlType declaringType, bool isAttachable) with a null XamlType.","commonSituations":"Building custom XAML type systems or invokers where the declaring type is looked up dynamically (e.g. schemaContext.GetXamlType returned null) and the null result is passed straight into the constructor.","solutions":["Ensure a valid non-null XamlType is created or looked up before constructing the XamlMember.","Check why GetXamlType returned null (unregistered assembly/namespace in the XamlSchemaContext) and register the type.","Wrap construction in a null check or use ArgumentNullException.ThrowIfNull on your own argument before forwarding."],"exampleFix":"// before\nvar member = new XamlMember(\"MyProp\", schemaContext.GetXamlType(typeof(MyType)), false);\n// after\nvar declaringType = schemaContext.GetXamlType(typeof(MyType)) ?? throw new InvalidOperationException(\"Type not registered in schema context\");\nvar member = new XamlMember(\"MyProp\", declaringType, false);","handlingStrategy":"validation","validationCode":"if (declaringType is null) throw new InvalidOperationException(\"declaringType must be resolved before creating a XamlMember\");","typeGuard":"bool IsValid(XamlType t) => t is not null;","tryCatchPattern":null,"preventionTips":["Always resolve the XamlType via GetXamlType and null-check before constructing XamlMember.","Register all types/assemblies with your XamlSchemaContext up front."],"tags":["xaml","null-argument","argument-validation"],"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"}