{"record":{"id":"dfa305552da70d91","repo":"dotnet/wpf","slug":"argumentnullexception","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs","lineNumber":30,"sourceCode":"    /// <summary>\n    /// ResourcePart is an implementation of the abstract PackagePart class. It contains an override for GetStreamCore.\n    /// </summary>\n    internal class ResourcePart : System.IO.Packaging.PackagePart\n    {\n        //------------------------------------------------------\n        //\n        //  Public Constructors\n        //\n        //------------------------------------------------------\n\n        #region Public Constructors\n\n        public ResourcePart(Package container, Uri uri, string name, ResourceManagerWrapper rmWrapper) :\n            base(container, uri)\n        {\n            if (rmWrapper == null)\n            {\n                throw new ArgumentNullException(nameof(rmWrapper));\n            }\n\n            _rmWrapper = rmWrapper;\n            _name = name;\n        }\n\n        #endregion\n\n        //------------------------------------------------------\n        //\n        //  Protected Methods\n        //\n        //------------------------------------------------------\n\n        #region Protected Methods\n\n        protected override Stream GetStreamCore(FileMode mode, FileAccess access)\n        {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs#L12-L48","documentation":"The ResourcePart constructor validates that the ResourceManagerWrapper it is given is non-null before storing it. Passing null means the part would have no way to locate its resource stream, so the constructor fails fast with ArgumentNullException naming the rmWrapper parameter.","triggerScenarios":"Calling new ResourcePart(container, uri, name, null), or an internal ResourceContainer.CreatePartCore path where a null ResourceManagerWrapper is supplied.","commonSituations":"Custom AppModel/package plumbing built on internal WPF APIs; initialization ordering bugs where the ResourceManager factory returns null; reflection-based construction with missing arguments.","solutions":["Ensure a valid ResourceManagerWrapper is constructed and passed to ResourcePart","Check that the ResourceManager/assembly used to build the wrapper initialized correctly","If constructing via reflection, supply the fourth argument explicitly"],"exampleFix":"// before\nvar part = new ResourcePart(container, uri, name, null);\n// after\nvar wrapper = new ResourceManagerWrapper(resourceManager);\nvar part = new ResourcePart(container, uri, name, wrapper);","handlingStrategy":"validation","validationCode":"if (rmWrapper == null) throw new InvalidOperationException(\"ResourceManagerWrapper must be initialized before creating a ResourcePart\");","typeGuard":"bool IsValid(ResourceManagerWrapper w) => w is not null;","tryCatchPattern":"try { var part = new ResourcePart(c, uri, name, rmWrapper); } catch (ArgumentNullException) { /* init wrapper first */ }","preventionTips":["Initialize ResourceManager wrappers before package/part construction","Use constructor argument validation in your own factory code","Avoid reflection-based construction of internal types"],"tags":["wpf","null-argument","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"}