{"record":{"id":"1254599a0dec525c","repo":"dotnet/wpf","slug":"sr-entryassemblyisnull","errorCode":null,"errorMessage":"SR.EntryAssemblyIsNull","messagePattern":"SR\\.EntryAssemblyIsNull","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourceContainer.cs","lineNumber":305,"sourceCode":"                }\n            }\n\n            if (rmwResult == ApplicationResourceManagerWrapper)\n            {\n                if (rmwResult != null)\n                {\n                    // If this is not a resource from a component then it might be\n                    // a content file and not an application resource.\n                    if (ContentFileHelper.IsContentFile(partName))\n                    {\n                        isContentFile = true;\n                        rmwResult = null;\n                    }\n                }\n                else\n                {\n                    // Throw when Application.ResourceAssembly is null. \n                    throw new IOException(SR.EntryAssemblyIsNull);\n                }\n            }\n\n            return rmwResult;\n        }\n\n        #endregion\n\n        //------------------------------------------------------\n        //\n        //  Private Fields\n        //\n        //------------------------------------------------------\n\n        #region Private Members\n\n        private static readonly Dictionary<string, ResourceManagerWrapper> s_registeredResourceManagers = new(StringComparer.Ordinal);\n        private static readonly Dictionary<string, ResourceManagerWrapper>.AlternateLookup<ReadOnlySpan<char>> s_registeredResourceManagersLookup = s_registeredResourceManagers.GetAlternateLookup<ReadOnlySpan<char>>();","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourceContainer.cs#L287-L323","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nvar part = package.GetPart(new Uri(\"images/logo.png\", UriKind.Relative));\n// after\nif (Application.ResourceAssembly == null)\n    Application.ResourceAssembly = typeof(App).Assembly;\nvar part = package.GetPart(new Uri(\"images/logo.png\", UriKind.Relative));","handlingStrategy":"validation","validationCode":"if (Application.ResourceAssembly == null)\n    Application.ResourceAssembly = typeof(App).Assembly;\n// then resolve the resource part","typeGuard":"static bool CanResolveResources() => Application.ResourceAssembly != null;","tryCatchPattern":"try\n{\n    part = package.GetPart(resourceUri);\n}\ncatch (IOException ex) when (ex.Message.Contains(SR.EntryAssemblyIsNull.ToString()))\n{\n    part = null; // fall back to manifest resource stream\n}","preventionTips":["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"],"tags":["wpf","resources","null-assembly","pack-uri"],"backgroundTag":"null-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"}