dotnet/wpf · error · IOException
SR.EntryAssemblyIsNull
Error message
SR.EntryAssemblyIsNull
What it means
ResourceContainer.GetResourceManagerWrapper builds a ResourceManager wrapper for resource parts in the application package. When Application.ResourceAssembly (the assembly backing application resources) is null — typically because no EntryAssembly is available — it throws IOException with SR.EntryAssemblyIsNull. Resources cannot be located without a resource assembly.
Solutions
- Set Application.ResourceAssembly to the assembly containing your resources before loading resource URIs.
- Ensure the host process has a valid entry assembly (avoid loading WPF resources from assemblies invoked without an entry point context).
- Defer resource loading until after Application startup completes.
- Catch IOException around resource resolution and fall back to explicit assembly resource loading (GetManifestResourceStream).
Example fix
// before
var part = package.GetPart(new Uri("images/logo.png", UriKind.Relative));
// after
if (Application.ResourceAssembly == null)
Application.ResourceAssembly = typeof(App).Assembly;
var part = package.GetPart(new Uri("images/logo.png", UriKind.Relative)); Defensive patterns
Strategy: validation
Validate before calling
if (Application.ResourceAssembly == null)
Application.ResourceAssembly = typeof(App).Assembly;
// then resolve the resource part Type guard
static bool CanResolveResources() => Application.ResourceAssembly != null;
Try / catch
try
{
part = package.GetPart(resourceUri);
}
catch (IOException ex) when (ex.Message.Contains(SR.EntryAssemblyIsNull.ToString()))
{
part = null; // fall back to manifest resource stream
} Prevention
- Always set Application.ResourceAssembly before pack URI resolution
- Load resources after Application startup, not in static constructors
- In hosted/plugin scenarios ensure an entry assembly exists
- Prefer explicit assembly resource APIs when no Application context exists
When it happens
Trigger: Accessing a resource part through a ResourceContainer-backed Package when Application.ResourceAssembly is null, e.g. resource pack URIs (pack://application:...) resolved before Application is initialized or in a host without an entry assembly.
Common situations: Unit tests or designers creating Application-derived contexts without setting ResourceAssembly; plugin/M Franework hosts where Assembly.GetEntryAssembly() returns null; loading BAML/resource parts too early in startup.
Related errors
- SR.BamlIsNotSupportedOutsideOfApplicationResources
- SR.NonPackAppAbsoluteUriNotAllowed
- requestUri.ToString() (WebExceptionStatus.RequestCanceled)
- SR.ApplicationShuttingDown
- SR.ChangingIdNotAllowed
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1254599a0dec525c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourceContainer.cs:305
}
}
if (rmwResult == ApplicationResourceManagerWrapper)
{
if (rmwResult != null)
{
// If this is not a resource from a component then it might be
// a content file and not an application resource.
if (ContentFileHelper.IsContentFile(partName))
{
isContentFile = true;
rmwResult = null;
}
}
else
{
// Throw when Application.ResourceAssembly is null.
throw new IOException(SR.EntryAssemblyIsNull);
}
}
return rmwResult;
}
#endregion
//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Members
private static readonly Dictionary<string, ResourceManagerWrapper> s_registeredResourceManagers = new(StringComparer.Ordinal);
private static readonly Dictionary<string, ResourceManagerWrapper>.AlternateLookup<ReadOnlySpan<char>> s_registeredResourceManagersLookup = s_registeredResourceManagers.GetAlternateLookup<ReadOnlySpan<char>>();View on GitHub (pinned to 81131a70a4)