{"record":{"id":"b347c04e68cc9010","repo":"dotnet/wpf","slug":"sr-documentreferencenotfound","errorCode":null,"errorMessage":"SR.DocumentReferenceNotFound","messagePattern":"SR\\.DocumentReferenceNotFound","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentReference.cs","lineNumber":275,"sourceCode":"\n\n        // sync load a document\n        private FixedDocument _LoadDocument()\n        {\n            FixedDocument idp = null;\n            Uri uriToLoad = _ResolveUri();\n            if (uriToLoad != null)\n            {\n                // Package-boundary guard. Reject any URI that escapes the XPS package.\n                XpsLoadingContext.EnforcePackageRelativeUri(((IUriContext)this).BaseUri, uriToLoad);\n\n                ContentType mimeType = null;\n                Stream docStream = null;\n\n                docStream = WpfWebRequestHelper.CreateRequestAndGetResponseStream(uriToLoad, out mimeType);\n                if (docStream == null)\n                {\n                    throw new ApplicationException(SR.DocumentReferenceNotFound);\n                }\n\n                ParserContext pc = new ParserContext\n                {\n                    BaseUri = uriToLoad\n                };\n\n                if (BindUriHelper.IsXamlMimeType(mimeType))\n                {\n                    XpsValidatingLoader loader = new XpsValidatingLoader();\n                    idp = loader.Load(docStream, ((IUriContext)this).BaseUri, pc, mimeType) as FixedDocument;\n                }\n                else if (MS.Internal.MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(mimeType))\n                {\n                    idp = XamlReader.LoadBaml(docStream, pc, null, true) as FixedDocument;\n                }\n                else\n                {","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentReference.cs#L257-L293","documentation":"DocumentReference._LoadDocument downloads the document at its Source URI and throws ApplicationException with SR.DocumentReferenceNotFound when the web response stream comes back null. This means WpfWebRequestHelper could not obtain a stream for the URI, i.e. the resource was not found or the request failed. It guards FixedDocumentSequence/XPS loading against silent null documents.","triggerScenarios":"Calling DocumentReference.GetDocument (or idpReloaded reload flow) when the Source URI points to a missing file, a wrong path, an unreachable server, or a handler that returns an empty/failed response so CreateRequestAndGetResponseStream returns null.","commonSituations":"Typo in the XPS/document path or pack URI; document served from a web server that returns 404; relative BaseUri resolved incorrectly after moving the app; file removed or renamed after build; running with restricted network/permissions in partial trust.","solutions":["Verify the DocumentReference.Source URI resolves to an existing document (fix the pack/file/http URI)","Use an absolute, correctly-formed pack URI (e.g. pack://application:,,,/Documents/FixedDocumentSequence.fdseq) instead of a broken relative path","Ensure the document file is included in project output (CopyToOutputDirectory) so it exists at runtime","Check the hosting web server/IIS actually serves the resource (test the URL in a browser) and the app has network access"],"exampleFix":"// before\ndocReference.Source = new Uri(\"Doc/fixdoc.xps\", UriKind.Relative);\n// after\ndocReference.Source = new Uri(\"pack://application:,,,/Doc/fixdoc.xps\", UriKind.Absolute);","handlingStrategy":"validation","validationCode":"bool docExists = uri != null && (uri.IsFile ? File.Exists(uri.LocalPath) : true); if (!docExists) throw new FileNotFoundException(uri?.ToString());","typeGuard":null,"tryCatchPattern":"try { var doc = docRef.GetDocument(); } catch (ApplicationException ex) { log.Error($\"Document at {docRef.Source} not found\", ex); ShowFallbackDocument(); }","preventionTips":["Verify pack URIs with a browser or direct request before use","Ship document files with the app and mark CopyToOutputDirectory","Use absolute pack URIs to avoid relative-resolution surprises","Handle load failures with a fallback UI"],"tags":["wpf","xps","uri-resolution","network"],"backgroundTag":"resource-not-found","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"}