{"record":{"id":"aff173f168351d1b","repo":"dotnet/wpf","slug":"sr-format-sr-unabletolocateresource-name","errorCode":null,"errorMessage":"SR.Format(SR.UnableToLocateResource, _name)","messagePattern":"SR\\.Format\\(SR\\.UnableToLocateResource, _name\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs","lineNumber":62,"sourceCode":"\n        #region Protected Methods\n\n        protected override Stream GetStreamCore(FileMode mode, FileAccess access)\n        {\n            Stream stream = null;\n\n            stream = EnsureResourceLocationSet();\n            // in order to find the resource we might have to open a stream.\n            // rather than waste the stream it is returned here and we can use it.\n            if (stream == null)\n            {\n                // Start looking for resources using the current ui culture.\n                // The resource manager will fall back to invariant culture automatically.\n                stream = _rmWrapper.GetStream(_name);\n\n                if (stream == null)\n                {\n                    throw new IOException(SR.Format(SR.UnableToLocateResource, _name));\n                }\n            }\n\n            // \n            // If this is a Baml stream, it will return BamlStream object, which contains\n            // both raw stream and the host assembly.\n            //\n            ContentType curContent = new ContentType(ContentType);\n\n            if (MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(curContent))\n            {\n                BamlStream bamlStream = new BamlStream(stream, _rmWrapper.Assembly);\n\n                stream = bamlStream;\n            }\n\n            return stream;\n        }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs#L44-L80","documentation":"GetStreamCore asks the ResourceManagerWrapper for a stream named _name; if the resource manager cannot locate that resource it returns null and the part throws IOException with SR.UnableToLocateResource naming the missing resource. This is the library's way of reporting a missing embedded resource.","triggerScenarios":"Requesting a resource part stream via GetStream()/GetStreamCore where the resource name does not exist in the assembly (missing .baml/.xaml resource, wrong casing, resource not embedded).","commonSituations":"Missing Build Action=Page/Resource in the csproj so the .baml was never embedded; renamed file without updating the pack URI; satellite assembly not deployed; pack URI case mismatch.","solutions":["Verify the resource exists: check the assembly with ildasm/ILSpy for the exact embedded resource name","Ensure the file's Build Action is Page or Resource in the project file","Fix casing/spelling in the pack URI — resource lookups are case-sensitive","Deploy required satellite/localized assemblies alongside the app"],"exampleFix":"// before\nvar uri = new Uri(\"pack://application:,,,/MyApp;component/views/mypage.xaml\"); // file is Views/MyPage.xaml, not embedded\n// after\n<!-- csproj --> <Page Include=\"Views\\MyPage.xaml\" />  // then the URI resolves","handlingStrategy":"validation","validationCode":"bool ResourceExists(Assembly asm, string name) => asm.GetManifestResourceNames().Any(n => n.EndsWith(name, StringComparison.OrdinalIgnoreCase));","typeGuard":null,"tryCatchPattern":"try { var s = part.GetStream(); } catch (IOException ex) when (ex.Message.Contains(\"Unable to locate\")) { /* fix resource name/build action */ }","preventionTips":["Check Build Action=Page/Resource in csproj for every XAML/data file","Compare pack URI names against GetManifestResourceNames output","Watch resource-name casing; lookups are case-sensitive","Ensure satellite assemblies ship with the app"],"tags":["wpf","resource-not-found","io"],"backgroundTag":"resource-not-found","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"}