{"record":{"id":"72d0f0b180bc03ee","repo":"PrismLibrary/Prism","slug":"resources-typewithkeynotregistered-formatted-with-key","errorCode":null,"errorMessage":"Resources.TypeWithKeyNotRegistered (formatted with key)","messagePattern":"Resources\\.TypeWithKeyNotRegistered \\(formatted with key\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Navigation/Regions/RegionBehaviorFactory.cs","lineNumber":86,"sourceCode":"            if (_registeredBehaviors.ContainsKey(behaviorKey)\n                && _registeredBehaviors[behaviorKey].Equals(behaviorType) == false)\n            {\n                _registeredBehaviors.Remove(behaviorKey);\n            }\n\n            AddIfMissing(behaviorKey, behaviorType);\n        }\n\n        /// <summary>\n        /// Creates an instance of the behavior <see cref=\"Type\"/> that is registered using the specified key.\n        /// </summary>\n        /// <param name=\"key\">The key that is used to register a behavior type.</param>\n        /// <returns>A new instance of the behavior. </returns>\n        public IRegionBehavior CreateFromKey(string key)\n        {\n            if (!ContainsKey(key))\n            {\n                throw new ArgumentException(\n                    string.Format(Thread.CurrentThread.CurrentCulture, Resources.TypeWithKeyNotRegistered, key), nameof(key));\n            }\n\n            return (IRegionBehavior)_container.Resolve(_registeredBehaviors[key]);\n        }\n\n\n        /// <summary>\n        /// Returns an enumerator that iterates through the collection.\n        /// </summary>\n        /// <returns>\n        /// A <see cref=\"T:System.Collections.Generic.IEnumerator`1\" /> that can be used to iterate through the collection.\n        /// </returns>\n        /// <filterpriority>1</filterpriority>\n        public IEnumerator<string> GetEnumerator()\n        {\n            return _registeredBehaviors.Keys.GetEnumerator();\n        }","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Navigation/Regions/RegionBehaviorFactory.cs#L68-L104","documentation":"RegionBehaviorFactory.CreateFromKey throws ArgumentException with the resource string Resources.TypeWithKeyNotRegistered when the requested behavior key was never registered with Attach. The factory can only create behaviors it knows about via its registration dictionary, so an unknown key is a caller bug.","triggerScenarios":"Calling CreateFromKey with a key that was never passed to Attach (e.g. typo in the behavior key, or CreateFromKey called before Attach registration, or key removed by Detach/ContainsKey check race).","commonSituations":"Custom region behaviors registered under different keys between Prism versions; copy-pasted factory code referencing old behavior keys; unit tests (ExistingBehavior_IsReplaced_WithCustomBehavior, MissingBehavior_IsAdded) exercising unregistered keys.","solutions":["Ensure Attach(key, behaviorType) was called for the exact key before CreateFromKey","Check key spelling/casing against the registered behavior key constants","If the behavior may not exist, call ContainsKey(key) first","Update keys after a Prism upgrade where built-in behavior keys changed"],"exampleFix":"// before\nvar b = factory.CreateFromKey(\"MyBehvior\");\n// after\nvar key = \"MyBehavior\";\nif (!factory.ContainsKey(key)) factory.Attach(key, typeof(MyBehavior));\nvar b = factory.CreateFromKey(key);","handlingStrategy":"validation","validationCode":"if (!factory.ContainsKey(key)) throw new InvalidOperationException($\"Behavior '{key}' not registered; call factory.Attach first\");\nvar behavior = factory.CreateFromKey(key);","typeGuard":null,"tryCatchPattern":"try { var b = factory.CreateFromKey(key); }\ncatch (ArgumentException ex) when (ex.ParamName == \"key\") { log.Warn($\"Unregistered region behavior key: {key}\"); }","preventionTips":["Centralize behavior keys as constants","Always Attach before CreateFromKey","Call ContainsKey as a pre-check for optional behaviors"],"tags":["prism","regions","argument-exception","key-not-registered"],"backgroundTag":"invalid-argument-value","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}