{"record":{"id":"d11f3ada1fbdb647","repo":"dotnet/wpf","slug":"webresponsefailure","errorCode":null,"errorMessage":"WebResponseFailure","messagePattern":"WebResponseFailure","errorType":"exception","errorClass":"WebException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebResponse.cs","lineNumber":847,"sourceCode":"        /// </summary>\n        private void WaitForResponse()\n        {\n#if DEBUG\n            if (PackWebRequestFactory._traceSwitch.Enabled)\n                System.Diagnostics.Trace.TraceInformation(\n                        DateTime.Now.ToLongTimeString() + \" \" + DateTime.Now.Millisecond + \" \" +\n                        Environment.CurrentManagedThreadId + \": \" +\n                        \"PackWebResponse.WaitForResponse()\");\n#endif\n            // wait for the response callback\n            _responseAvailable.WaitOne();\n\n            // We get here only when the other thread signals.\n            // Need to inspect for errors and throw if there was trouble on the other thread.\n            if (_responseError)\n            {\n                if (_responseException == null)\n                    throw new WebException(SR.WebResponseFailure);\n                else\n                    throw _responseException;   // throw literal exception if there is one\n            }\n        }\n\n        /// <summary>\n        /// Timeout callback\n        /// </summary>\n        /// <param name=\"stateInfo\"></param>\n        private void TimeoutCallback(Object stateInfo)\n        {\n            lock (_lockObject)   // prevent race condition accessing _timeoutTimer, _disposed, _responseAvailable\n            {\n                // If disposed, the message is too late\n                // Exit early and don't access members as they have been disposed\n                // Let Close() method clean up our Timer object\n                if (_disposed)\n                    return;","sourceCodeStart":829,"sourceCodeEnd":865,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebResponse.cs#L829-L865","documentation":"PackWebResponse performs its real work on a background thread; consumers block in WaitForResponse, which rethrows the outcome. If the worker signaled _responseError without an accompanying exception object, WaitForResponse throws WebException(SR.WebResponseFailure); otherwise it rethrows the original exception. This pattern is hit by GetResponseStream, InnerResponse, Headers, ResponseUri, IsFromCache, and ContentType.","triggerScenarios":"Accessing any PackWebResponse result member after the asynchronous response worker failed — e.g. underlying WebRequest.GetResponse threw, stream read failed, or container open failed on the worker thread.","commonSituations":"Network failure or server error while downloading the outer package; invalid package bytes that break Package.Open on the background thread; aborted/disposed request racing with a response access.","solutions":["Inspect and fix the underlying cause (check inner _responseException / inner WebException status — DNS, 404, TLS, etc.).","Retry the request if the failure was transient network error.","Ensure the request/response objects are not disposed or aborted before the response is consumed.","Validate the served content is a valid package before consuming it."],"exampleFix":"// before\nvar resp = req.GetResponse();\nvar s = resp.GetResponseStream(); // WebResponseFailure here\n// after\ntry {\n    var s = req.GetResponse().GetResponseStream();\n} catch (WebException ex) {\n    // inspect ex.Status / inner exception, retry or surface\n}","handlingStrategy":"retry","validationCode":"// pre-flight: ensure request not disposed and outer transport URI is reachable\nif (req == null || req.RequestUri.HostNameType == UriHostNameType.Unknown) throw new InvalidOperationException(\"invalid pack request\");","typeGuard":null,"tryCatchPattern":"try { return resp.GetResponseStream(); }\ncatch (WebException ex) when (ex.Status == WebExceptionStatus.ConnectFailure || ex.Status == WebExceptionStatus.Timeout) { /* retry with backoff */ }\ncatch (WebException ex) { /* surface inner exception ex.InnerException */ throw; }","preventionTips":["Consume the response promptly and don't dispose the request mid-flight","Inspect WebException.Status and InnerException to find the root cause","Implement retry with backoff for transient network errors","Validate that the served bytes form a valid package before use"],"tags":["wpf","packaging","async","webresponse"],"backgroundTag":"http-request-failed","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"}