dotnet/wpf · error · IOException

GetResponseFailed (requestUri)

Error message

GetResponseFailed (requestUri)

What it means

WpfWebRequestHelper.GetResponse throws IOException with SR.GetResponseFailed when the underlying WebRequest returns a null WebResponse. Since it is unclear whether WebRequest.GetResponse can ever return null, this is a defensive check carried over from v1 code; the message embeds the request URI relative to the pack application base.

Solutions

  1. Catch IOException around resource-loading calls and inspect the embedded requestUri to identify the failing resource.
  2. Verify the resource URI is valid and the resource exists (pack://application:,,,/... with correct assembly/component syntax).
  3. Check inner/logged WebExceptions from the underlying request for the root cause.

Example fix

// before
var resp = WpfWebRequestHelper.CreateRequestAndGetResponse(request);
// after
try { var resp = WpfWebRequestHelper.CreateRequestAndGetResponse(request); }
catch (IOException ex) { log.Error("Resource load failed: " + uri, ex); throw; }
Defensive patterns

Strategy: try-catch

Validate before calling

if (request == null || request.RequestUri == null)
    throw new InvalidOperationException("Request and RequestUri must be set before calling GetResponse.");

Try / catch

try { var resp = WpfWebRequestHelper.CreateRequestAndGetResponse(request); }
catch (IOException ex)
{ throw new InvalidOperationException("Resource load failed: " + request.RequestUri, ex); }

Prevention

When it happens

Trigger: Calling CreateRequestAndGetResponse (or the response-consuming path) where the underlying WebRequest.GetResponse() returns null, e.g. for scheme handlers that fail silently.

Common situations: Loading application resources when the pack web-request pipeline returns no response, often downstream of a malformed URI or an aborted request.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/WpfWebRequestHelper.cs:226

        WebRequest request = CreateRequest(uri);
        return GetResponse(request);
    }

    internal static WebResponse GetResponse(WebRequest request)
    {
        WebResponse response = request.GetResponse();
        
        // 'is' is used here instead of exact type checks to allow for the (remote) possibility that an internal
        // implementation type derived from HttpWebRequest/Response may be used by System.Net.
        if (response is HttpWebResponse && !(request is HttpWebRequest))
            throw new ArgumentException();
        
        // It is not clear whether WebRequest.GetRespone() can ever return null, but some of the v1 code had
        // this check, so it is added here just in case.
        if (response == null)
        {
            Uri requestUri = BaseUriHelper.PackAppBaseUri.MakeRelativeUri(request.RequestUri);
            throw new IOException(SR.Format(SR.GetResponseFailed, requestUri.ToString()));
        }
        
        HandleWebResponse(response);
        return response;
    }
    internal static WebResponse EndGetResponse(WebRequest request, IAsyncResult ar)
    {
        WebResponse response = request.EndGetResponse(ar);
        if (response is HttpWebResponse && !(request is HttpWebRequest))
            throw new ArgumentException();
        // It is not clear whether WebRequest.GetRespone() can ever return null, but some of the v1 code had
        // this check, so it is added here just in case.
        if (response == null)
        {
            Uri requestUri = BaseUriHelper.PackAppBaseUri.MakeRelativeUri(request.RequestUri);
            throw new IOException(SR.Format(SR.GetResponseFailed, requestUri.ToString()));
        }
        HandleWebResponse(response);

View on GitHub (pinned to 81131a70a4)