{"record":{"id":"7cfbe64735b2020b","repo":"dotnet/wpf","slug":"sr-format-sr-unabletolocateresource-uri-tostring","errorCode":null,"errorMessage":"SR.Format(SR.UnableToLocateResource, Uri.ToString())","messagePattern":"SR\\.Format\\(SR\\.UnableToLocateResource, Uri\\.ToString\\(\\)\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs","lineNumber":75,"sourceCode":"                string assemblyName, assemblyVersion, assemblyKey;\n                string filePath;\n\n                // For now, only Application assembly supports content files, \n                // so we can simply ignore the assemblyname etc.\n                // In the future, we may extend this support for regular library assembly,\n                // assemblyName will be used to predict the right file path.\n\n                BaseUriHelper.GetAssemblyNameAndPart(Uri, out filePath, out assemblyName, out assemblyVersion, out assemblyKey);\n\n                // filePath should not have leading slash.  GetAssemblyNameAndPart( ) can guarantee it.\n                _fullPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(location), filePath);\n            }\n\n            stream = CriticalOpenFile(_fullPath);\n\n            if (stream == null)\n            {\n                throw new IOException(SR.Format(SR.UnableToLocateResource, Uri.ToString()));\n            }\n\n            return stream;\n        }\n\n        protected override string GetContentTypeCore()\n        {\n            return MS.Internal.MimeTypeMapper.GetMimeTypeFromUri(new Uri(Uri.ToString(), UriKind.RelativeOrAbsolute)).ToString();\n        }\n\n        #endregion\n\n        //------------------------------------------------------\n        //\n        //  Private Methods\n        //\n        //------------------------------------------------------\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs#L57-L93","documentation":"ContentFilePart.GetStreamCore opens the file backing a content-file package part from the deployment directory. When CriticalOpenFile returns null — the resolved _fullPath does not exist or cannot be opened — the part throws IOException with 'UnableToLocateResource' plus the part URI. This signals that a resource the application manifest claims to include is missing at the expected location.","triggerScenarios":"Opening a stream from a ContentFilePart (e.g. via application/resource part APIs on a Package created from a deployed ClickOnce/WPF app) when the file at _fullPath is absent or unreadable.","commonSituations":"ClickOnce deployment where a content file was not published; application files moved or deleted from the deployment folder; manifest references a file excluded from build output; partial/corrupted deployment cache.","solutions":["Verify the file referenced by the URI exists at the deployment/application files location and is included in the ClickOnce manifest.","Rebuild and republish the application ensuring the content file is copied to output and marked as Content in the project file.","Clear the ClickOnce cache (mage -cc or delete the app's 2.0 folder under Local Settings Apps) and reinstall.","Catch IOException and fall back to a embedded-resource lookup (GetManifestResourceStream) as a resilience measure."],"exampleFix":"// before\nusing var s = contentFilePart.GetStream();\n// after\nif (!File.Exists(resolvedPath))\n    throw new FileNotFoundException($\"Deployed content file missing: {resolvedPath}\");\nusing var s = contentFilePart.GetStream();","handlingStrategy":"try-catch","validationCode":"string path = ResolveDeploymentPath(partUri);\nif (string.IsNullOrEmpty(path) || !File.Exists(path))\n    throw new FileNotFoundException($\"Deployed resource missing: {partUri}\", path);","typeGuard":null,"tryCatchPattern":"try\n{\n    stream = part.GetStream();\n}\ncatch (IOException ex) when (ex.Message.Contains(\"UnableToLocateResource\"))\n{\n    stream = LoadFromEmbeddedResources(partUri);\n}","preventionTips":["Verify content files are marked as Content and CopyToOutputDirectory is set","Publish the ClickOnce app fully after adding resource files","Clear stale ClickOnce caches when deployments change","Log resolved _fullPath to diagnose path mismatches"],"tags":["wpf","clickonce","file-not-found","deployment"],"backgroundTag":"file-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"}