{"record":{"id":"bc111d1e5369eb18","repo":"dotnet/wpf","slug":"sr-failedtoconvertresource","errorCode":null,"errorMessage":"SR.FailedToConvertResource","messagePattern":"SR\\.FailedToConvertResource","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs","lineNumber":2916,"sourceCode":"                    }\n                }\n                else\n                {\n                    try\n                    {\n                        // If o == null, it means we don't know how to convert it.\n                        // Currently that's everything other than xaml, baml and html at site\n                        // of origin. If this is not a TopLevelContainer, we will throw an exception\n                        // if there is no converter for it, else we will try to launch the\n                        // browser if safe to do so.\n                        // For loose XAML viewing, we can get in this situation if the web server doesn't\n                        // return the right MIME type. UrlMon in IE 7+ has some heuristics based on file extension\n                        // to detect XAML, so PresentationHost may get invoked, but our\n                        // WpfWebRequestHelper.GetContentType() fails to do the same inference. In particular,\n                        // it appears that UrlMon looks at the Content-Disposition HTTP header, but we don't.\n                        if (!IsTopLevelContainer)\n                        {\n                            throw new InvalidOperationException(SR.FailedToConvertResource);\n                        }\n\n                        DelegateToBrowser(response is PackWebResponse, destinationUri);\n\n                        // Beware reentrancy in the context of the outgoing DelegateNavigation call:\n                        // The browser will send us the BrowseStop command before returning from Navigate().\n                        // This will lead to DoStopLoading(), which will abort the WebReqest.\n                    }\n                    finally\n                    {\n                        DrainResponseStreamForPartialCacheFileBug(s);\n\n                        s.Close();\n\n                        // Should clean the state.\n                        ResetPendingNavigationState(_navStatus);\n                    }\n                }","sourceCodeStart":2898,"sourceCodeEnd":2934,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs#L2898-L2934","documentation":"During async download handling, when the response is not a top-level container, NavigationService cannot convert the downloaded resource into a displayable object and throws. The server returned content that WPF cannot interpret as a XAML page or document for navigation.","triggerScenarios":"Navigating to a URI whose HTTP response content type cannot be converted to a WPF object in a non-top-level container (e.g. an inner Frame), commonly when the server sends XAML or binary content with an unexpected/unrecognized MIME type.","commonSituations":"Server misconfiguration returning wrong Content-Type for .xaml files; navigating a Frame to a non-XAML resource; WpfWebRequestHelper.GetContentType failing to infer XAML where IE/UrlMon would.","solutions":["Ensure the server returns the correct Content-Type (application/xaml+xml for XAML pages).","Navigate only to XAML/resource URIs the WPF converter supports in that frame.","Serve loose XAML through a properly configured web server (MIME mapping present).","Handle NavigationFailed and log the destination URI to diagnose the content type."],"exampleFix":"// server web.config: ensure MIME map\n// before: <mimeMap fileExtension=\".xaml\" mimeType=\"application/octet-stream\" />\n// after: <mimeMap fileExtension=\".xaml\" mimeType=\"application/xaml+xml\" />","handlingStrategy":"validation","validationCode":"// client-side precheck: request headers and confirm content type before navigating\nvar req = WebRequest.Create(uri);\nusing (var resp = req.GetResponse())\n    bool ok = ((HttpWebResponse)resp).ContentType.StartsWith(\"application/xaml+xml\");","typeGuard":"bool IsXamlUri(Uri u) => u != null && (u.AbsolutePath.EndsWith(\".xaml\", StringComparison.OrdinalIgnoreCase) || u.AbsolutePath.EndsWith(\".xbap\", StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try { frame.Navigate(uri); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"convert\"))\n{ frame.NavigationService.StopLoading(); ShowUnsupportedContentError(uri); }","preventionTips":["Configure server MIME types: .xaml = application/xaml+xml.","Verify Content-Type with curl -I before deploying.","Keep target pages as compiled XAML where possible.","Handle Frame.NavigationFailed to surface diagnostics."],"tags":["wpf","navigation","http","content-type"],"backgroundTag":"unexpected-response-shape","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"}