{"record":{"id":"ca6dbea3cd9f2274","repo":"dotnet/wpf","slug":"sr-nulltypeillegal","errorCode":null,"errorMessage":"SR.NullTypeIllegal","messagePattern":"SR\\.NullTypeIllegal","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs","lineNumber":544,"sourceCode":"        internal void Seal(FrameworkTemplate ownerTemplate)\n        {\n            if (_sealed)\n            {\n                return;\n            }\n\n            // Store owner Template\n            _frameworkTemplate = ownerTemplate;\n\n            // Perform actual Seal operation\n            Seal();\n        }\n\n        private void Seal()\n        {\n            if (_type == null && _text == null)\n            {\n                throw new InvalidOperationException(SR.NullTypeIllegal);\n            }\n\n            if (_firstChild != null)\n            {\n                // This factory has children, it must implement IAddChild so that these\n                // children can be added to the logical tree\n                if (!typeof(IAddChild).IsAssignableFrom(_type))\n                {\n                    throw new InvalidOperationException(SR.Format(SR.TypeMustImplementIAddChild, _type.Name));\n                }\n            }\n\n            ApplyAutoAliasRules();\n\n            if ((_childName != null) && (_childName != String.Empty))\n            {\n                // ChildName provided\n                if (!IsChildNameValid(_childName))","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs#L526-L562","documentation":"The private Seal throws InvalidOperationException when the factory has neither a Type nor Text set. A FrameworkElementFactory must know what element to create; sealing with both _type and _text null means no valid factory content was configured. This fires when the factory is being finalized (e.g. when a template using it is being sealed).","triggerScenarios":"Sealing a template whose VisualTree is an empty FrameworkElementFactory created with the parameterless constructor and never assigned a type, text, or children context.","commonSituations":"new FrameworkElementFactory() left unconfigured but attached to a DataTemplate/ControlTemplate; conditional configuration code paths that skip setting the type.","solutions":["Construct the factory with a target type: new FrameworkElementFactory(typeof(TargetElement)).","If textual content is intended, set the factory's Text property.","Ensure the configuration path actually runs before assigning the factory to a template."],"exampleFix":"// before\nvar factory = new FrameworkElementFactory();\ntemplate.VisualTree = factory;\n// after\nvar factory = new FrameworkElementFactory(typeof(Border));\ntemplate.VisualTree = factory;","handlingStrategy":"validation","validationCode":"if (factory.GetType() == null && string.IsNullOrEmpty(factory.Text))\n    throw new InvalidOperationException(\"Factory needs a Type or Text before sealing.\");","typeGuard":"static bool IsConfigured(FrameworkElementFactory f) => f != null && (f.Type != null || !string.IsNullOrEmpty(f.Text));","tryCatchPattern":"try { template.Seal(); }\ncatch (InvalidOperationException) { template.VisualTree = new FrameworkElementFactory(typeof(DefaultContent)); }","preventionTips":["Always use the FrameworkElementFactory(Type) constructor unless text content is intended.","Verify every code path sets a type/text before template assignment.","Fail fast in factory creation helpers with a guard."],"tags":["wpf","template","uninitialized"],"backgroundTag":"missing-required-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"}