dotnet/wpf · error · IOException

SR.UnableToLocateResource

Error message

SR.UnableToLocateResource

What it means

SplashScreen.Show throws IOException when GetResourceStream() returns null, wrapping SR.UnableToLocateResource with the resource name. The splash resource could not be found in the assembly's generated .g resources, so the splash window cannot be created.

Solutions

  1. Ensure the image exists in the project with Build Action = Resource so it is compiled into assemblyname.g
  2. Verify the resourceName passed to the constructor matches the embedded name (extension included, path-relative)
  3. Confirm you are passing the assembly that actually contains the resource
  4. Catch IOException around Show and degrade gracefully (skip splash)
  5. Check the .g.resources content (e.g. via ILSpy/AssemblyReader) to confirm the exact resource key

Example fix

// before
splash.Show(false); // IOException: UnableToLocateResource
// after
try { splash.Show(false); }
catch (IOException ex) { Trace.WriteLine($"Splash skipped: {ex.Message}"); }
Defensive patterns

Strategy: try-catch

Validate before calling

bool resourceExists = Assembly.GetExecutingAssembly()
    .GetManifestResourceNames()
    .Any(n => n.EndsWith(".g.resources") );
// or verify via ResourceManager GetStream before Show

Type guard

bool SplashResourceAvailable(SplashScreen s, ResourceManager rm, string name) => rm.GetStream(name) != null;

Try / catch

try { splash.Show(false); } catch (IOException ex) { Trace.WriteLine($"Splash resource missing: {ex.Message}"); /* continue startup */ }

Prevention

When it happens

Trigger: Calling Show (or Show(false, true)) when the named resource is not embedded in the assembly — resource file missing, wrong Build Action (not 'Resource'), file excluded from the project, or name case/extension mismatch.

Common situations: Switching build configurations that skip the resource; renaming the splash image without updating the constructor argument; resource in a satellite/other assembly than the one passed to the constructor; MSBuild Resource inclusion removed during migration.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/9019b1968bcec582. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/SplashScreen.cs:75

        }

        public void Show(bool autoClose)
        {
            Show(autoClose, topMost: false);
        }

        public unsafe void Show(bool autoClose, bool topMost)
        {
            if (!_hwnd.IsNull)
            {
                return;
            }

            // If we've already been shown it isn't an error to call show
            // again (maybe you forgot) since you will still be shown state.

            using UnmanagedMemoryStream resourceStream = GetResourceStream()
                ?? throw new IOException(SR.Format(SR.UnableToLocateResource, _resourceName));

            resourceStream.Seek(0, SeekOrigin.Begin); // ensure stream position

            CreateLayeredWindowFromImgBuffer(new(resourceStream.PositionPointer, (int)resourceStream.Length), topMost);

            if (autoClose)
            {
                Dispatcher.CurrentDispatcher.BeginInvoke(
                    DispatcherPriority.Loaded,
                    (DispatcherOperationCallback)(static arg =>
                    {
                        ((SplashScreen)arg).Close(TimeSpan.FromSeconds(0.3));
                        return null;
                    }),
                    this);
            }

            // The HWND that we just created is owned by this thread.  When we close we should ensure that it 

View on GitHub (pinned to 81131a70a4)