{"record":{"id":"40a51d7b365bb2b8","repo":"icsharpcode/ILSpy","slug":"xmldoc-filename-is-redirecting-to-redirect-bu","errorCode":null,"errorMessage":"XmlDoc {fileName} is redirecting to {redirect}, but that file was not found.","messagePattern":"XmlDoc (.+?) is redirecting to (.+?), but that file was not found\\.","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs","lineNumber":179,"sourceCode":"\t\t\t\t\t\tstring redirectionTarget = GetRedirectionTarget(fileName, xmlReader.GetAttribute(\"redirect\"));\r\n\t\t\t\t\t\tif (redirectionTarget != null)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tDebug.WriteLine(\"XmlDoc \" + fileName + \" is redirecting to \" + redirectionTarget);\r\n\t\t\t\t\t\t\tusing (FileStream redirectedFs = new FileStream(redirectionTarget, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tusing (XmlTextReader redirectedXmlReader = new XmlTextReader(redirectedFs))\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tredirectedXmlReader.XmlResolver = null; // no DTD resolving\r\n\t\t\t\t\t\t\t\t\tredirectedXmlReader.MoveToContent();\r\n\t\t\t\t\t\t\t\t\tthis.fileName = redirectionTarget;\r\n\t\t\t\t\t\t\t\t\tthis.encoding = redirectedXmlReader.Encoding;\r\n\t\t\t\t\t\t\t\t\tReadXmlDoc(redirectedXmlReader);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tthrow new XmlException(\"XmlDoc \" + fileName + \" is redirecting to \" + xmlReader.GetAttribute(\"redirect\") + \", but that file was not found.\");\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic string GetRedirectionTarget(string xmlFileName, string target)\r\n\t\t{\r\n\t\t\tstring programFilesDir = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);\r\n\t\t\tprogramFilesDir = AppendDirectorySeparator(programFilesDir);\r\n\r\n\t\t\tstring corSysDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();\r\n\t\t\tcorSysDir = AppendDirectorySeparator(corSysDir);\r\n\r\n\t\t\tvar fileName = target.Replace(\"%PROGRAMFILESDIR%\", programFilesDir)\r\n\t\t\t\t.Replace(\"%CORSYSDIR%\", corSysDir);\r\n\t\t\tif (!Path.IsPathRooted(fileName))\r\n\t\t\t\tfileName = Path.Combine(Path.GetDirectoryName(xmlFileName), fileName);\r","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs#L161-L197","documentation":"XmlException thrown by the XmlDocumentationProvider constructor when a doc XML file declares a 'redirect' attribute but GetRedirectionTarget returns null, i.e. XmlDocLoader.LookupLocalizedXmlDoc could not find the redirected file on disk. Framework doc files commonly redirect via '%CORSYSDIR%' / '%PROGRAMFILESDIR%' placeholders, so a missing SDK/reference-assembly install or a non-Windows platform (empty ProgramFilesX86) produces this.","triggerScenarios":"Constructing XmlDocumentationProvider for a .NET Framework XML doc file whose redirect target does not exist; running on Linux/macOS where Environment.SpecialFolder.ProgramFilesX86 is empty and the redirected path does not resolve.","commonSituations":"Decompiling with framework XML doc loading enabled on a machine without the matching .NET Framework SDK / reference assemblies installed; relocation of the doc file the redirect points to; redirected path behind a placeholder that expands to nothing on the current OS.","solutions":["Install the .NET Framework Developer Pack / reference assemblies that supply the redirected XML doc file.","On non-Windows, point the doc loader at a local copy of the redirected file or disable framework XML doc loading.","Wrap construction in a try/catch for XmlException and fall back to no XML docs for that assembly."],"exampleFix":"// before\nvar provider = new XmlDocumentationProvider(fileName);\n\n// after\nXmlDocumentationProvider provider;\ntry\n{\n    provider = new XmlDocumentationProvider(fileName);\n}\ncatch (XmlException)\n{\n    provider = null; // no doc available for this assembly\n}","handlingStrategy":"try-catch","validationCode":"var provider = new XmlDocumentationProvider(fileName); // no safe pre-check; the redirect target is resolved internally\n// At the call site, simply tolerate absence:\nXmlDocumentationProvider TryLoad(string f)\n{\n    try { return new XmlDocumentationProvider(f); }\n    catch (XmlException) { return null; }\n    catch (IOException) { return null; }\n}","typeGuard":null,"tryCatchPattern":"try { provider = new XmlDocumentationProvider(fileName); }\ncatch (XmlException ex) { logger.Warn($\"XML doc unavailable for {fileName}: {ex.Message}\"); provider = null; }","preventionTips":["Install the .NET Framework reference assemblies / Developer Pack that the redirect targets.","On non-Windows, disable framework XML doc loading or supply local copies.","Treat XML doc loading as optional: catch XmlException and degrade gracefully."],"tags":["xml-doc","redirect","file-not-found","framework-docs"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}