dotnet/wpf · error · InvalidOperationException
SR.Format(SR.PropertyIsImmutable, "ResourceAssembly"…
Error message
SR.Format(SR.PropertyIsImmutable, "ResourceAssembly", "Application")
What it means
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.
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
Example fix
// before
Application.ResourceAssembly = newAssembly; // throws if already set
// after
if (Application.ResourceAssembly != newAssembly)
throw new InvalidOperationException("ResourceAssembly already fixed; use pack URIs for other assemblies"); Defensive patterns
Strategy: validation
Validate before calling
bool canSetAssembly(Assembly a) => Application.ResourceAssembly == null || Application.ResourceAssembly == a;
Try / catch
try { Application.ResourceAssembly = asm; } catch (InvalidOperationException) { /* already fixed; use pack URIs with assembly names */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Resource resolution failures prompting developers to 'fix' the assembly at runtime; satellite/localization assemblies swapped dynamically; test frameworks running multiple apps in one process.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SR.ApplicationShuttingDown
- CurrentFixedPageWriter uninitialized
- FixedPageReader
- SR.AnnotationServiceNotEnabled
- SR.BamlIsNotSupportedOutsideOfApplicationResources
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/45b1a645ada45be6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:1095
}
}
return _resourceAssembly;
}
set
{
lock (_globalLock)
{
if (_resourceAssembly != value)
{
if ((_resourceAssembly == null) && (Assembly.GetEntryAssembly() == null))
{
_resourceAssembly = value;
BaseUriHelper.ResourceAssembly = value;
}
else
{
throw new InvalidOperationException(SR.Format(SR.PropertyIsImmutable, "ResourceAssembly", "Application"));
}
}
}
}
}
#endregion Public Properties
//------------------------------------------------------
//
// Public Events
//
//------------------------------------------------------
#region Public Events
/// <summary>
/// The Startup event is fired when an application is starting.
/// This event is raised by the OnStartup method.View on GitHub (pinned to 81131a70a4)