dotnet/wpf · error · IOException
SR.Format(SR.UnableToLocateResource, _name)
Error message
SR.Format(SR.UnableToLocateResource, _name)
What it means
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.
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
Example fix
// before
var uri = new Uri("pack://application:,,,/MyApp;component/views/mypage.xaml"); // file is Views/MyPage.xaml, not embedded
// after
<!-- csproj --> <Page Include="Views\MyPage.xaml" /> // then the URI resolves Defensive patterns
Strategy: validation
Validate before calling
bool ResourceExists(Assembly asm, string name) => asm.GetManifestResourceNames().Any(n => n.EndsWith(name, StringComparison.OrdinalIgnoreCase));
Try / catch
try { var s = part.GetStream(); } catch (IOException ex) when (ex.Message.Contains("Unable to locate")) { /* fix resource name/build action */ } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- ArgumentOutOfRangeException(nameof(offset))
- can’t seek on baseStream
- Cannot perform this function on a stream that does not…
- Image_CannotCreateTempFile
- No file exists at
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/aff173f168351d1b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs:62
#region Protected Methods
protected override Stream GetStreamCore(FileMode mode, FileAccess access)
{
Stream stream = null;
stream = EnsureResourceLocationSet();
// in order to find the resource we might have to open a stream.
// rather than waste the stream it is returned here and we can use it.
if (stream == null)
{
// Start looking for resources using the current ui culture.
// The resource manager will fall back to invariant culture automatically.
stream = _rmWrapper.GetStream(_name);
if (stream == null)
{
throw new IOException(SR.Format(SR.UnableToLocateResource, _name));
}
}
//
// If this is a Baml stream, it will return BamlStream object, which contains
// both raw stream and the host assembly.
//
ContentType curContent = new ContentType(ContentType);
if (MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(curContent))
{
BamlStream bamlStream = new BamlStream(stream, _rmWrapper.Assembly);
stream = bamlStream;
}
return stream;
}View on GitHub (pinned to 81131a70a4)