{"record":{"id":"45b1a645ada45be6","repo":"dotnet/wpf","slug":"sr-format-sr-propertyisimmutable-resourceassembly","errorCode":null,"errorMessage":"SR.Format(SR.PropertyIsImmutable, \"ResourceAssembly\", \"Application\")","messagePattern":"SR\\.Format\\(SR\\.PropertyIsImmutable, \"ResourceAssembly\", \"Application\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs","lineNumber":1095,"sourceCode":"                    }\n                }\n\n                return _resourceAssembly;\n            }\n            set\n            {\n                lock (_globalLock)\n                {\n                    if (_resourceAssembly != value)\n                    {\n                        if ((_resourceAssembly == null) && (Assembly.GetEntryAssembly() == null))\n                        {\n                            _resourceAssembly = value;\n                            BaseUriHelper.ResourceAssembly = value;\n                        }\n                        else\n                        {\n                            throw new InvalidOperationException(SR.Format(SR.PropertyIsImmutable, \"ResourceAssembly\", \"Application\"));\n                        }\n                    }\n                }\n            }\n        }\n\n        #endregion Public Properties\n\n        //------------------------------------------------------\n        //\n        //  Public Events\n        //\n        //------------------------------------------------------\n\n        #region Public Events\n        /// <summary>\n        ///     The Startup event is fired when an application is starting.\n        ///     This event is raised by the OnStartup method.","sourceCodeStart":1077,"sourceCodeEnd":1113,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs#L1077-L1113","documentation":"Application.ResourceAssembly can only be set once. After the resource assembly has been established (either explicitly or implicitly when the Application is constructed), any attempt to assign a different value throws InvalidOperationException stating the property is immutable. Re-assigning the same value is allowed.","triggerScenarios":"Setting Application.ResourceAssembly a second time with a different Assembly, e.g. in multi-assembly plugin scenarios or after Application.Current already initialized it; unit tests reconfiguring the resource assembly per test.","commonSituations":"Resource resolution failures prompting developers to 'fix' the assembly at runtime; satellite/localization assemblies swapped dynamically; test frameworks running multiple apps in one process.","solutions":["Set ResourceAssembly once, at startup, before any resource lookups occur","Check Application.ResourceAssembly != value before assigning","If resources live in another assembly, reference them via pack URIs with the assembly name (pack://application:,,,/MyLib;component/x.png) instead of changing ResourceAssembly","Restart the application/process rather than reassigning the assembly"],"exampleFix":"// before\nApplication.ResourceAssembly = newAssembly; // throws if already set\n// after\nif (Application.ResourceAssembly != newAssembly)\n    throw new InvalidOperationException(\"ResourceAssembly already fixed; use pack URIs for other assemblies\");","handlingStrategy":"validation","validationCode":"bool canSetAssembly(Assembly a) => Application.ResourceAssembly == null || Application.ResourceAssembly == a;","typeGuard":null,"tryCatchPattern":"try { Application.ResourceAssembly = asm; } catch (InvalidOperationException) { /* already fixed; use pack URIs with assembly names */ }","preventionTips":["Set ResourceAssembly exactly once at startup","Use pack URIs with ;component/ for cross-assembly resources","Never swap assemblies at runtime","Guard assignments with an equality check"],"tags":["wpf","resources","immutable","assembly","lifecycle"],"backgroundTag":"unsupported-operation","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"}