icsharpcode/ILSpy · error · XmlException

XmlDoc {fileName} is redirecting to {redirect}, but that fil

Error message

XmlDoc {fileName} is redirecting to {redirect}, but that file was not found.

What it means

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.

Source

Thrown at ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs:179

						string redirectionTarget = GetRedirectionTarget(fileName, xmlReader.GetAttribute("redirect"));
						if (redirectionTarget != null)
						{
							Debug.WriteLine("XmlDoc " + fileName + " is redirecting to " + redirectionTarget);
							using (FileStream redirectedFs = new FileStream(redirectionTarget, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete))
							{
								using (XmlTextReader redirectedXmlReader = new XmlTextReader(redirectedFs))
								{
									redirectedXmlReader.XmlResolver = null; // no DTD resolving
									redirectedXmlReader.MoveToContent();
									this.fileName = redirectionTarget;
									this.encoding = redirectedXmlReader.Encoding;
									ReadXmlDoc(redirectedXmlReader);
								}
							}
						}
						else
						{
							throw new XmlException("XmlDoc " + fileName + " is redirecting to " + xmlReader.GetAttribute("redirect") + ", but that file was not found.");
						}
					}
				}
			}
		}

		static string GetRedirectionTarget(string xmlFileName, string target)
		{
			string programFilesDir = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
			programFilesDir = AppendDirectorySeparator(programFilesDir);

			string corSysDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
			corSysDir = AppendDirectorySeparator(corSysDir);

			var fileName = target.Replace("%PROGRAMFILESDIR%", programFilesDir)
				.Replace("%CORSYSDIR%", corSysDir);
			if (!Path.IsPathRooted(fileName))
				fileName = Path.Combine(Path.GetDirectoryName(xmlFileName), fileName);

View on GitHub (pinned to 60c08fcb74)

Solutions

  1. Install the .NET Framework Developer Pack / reference assemblies that supply the redirected XML doc file.
  2. On non-Windows, point the doc loader at a local copy of the redirected file or disable framework XML doc loading.
  3. Wrap construction in a try/catch for XmlException and fall back to no XML docs for that assembly.

Example fix

// before
var provider = new XmlDocumentationProvider(fileName);

// after
XmlDocumentationProvider provider;
try
{
    provider = new XmlDocumentationProvider(fileName);
}
catch (XmlException)
{
    provider = null; // no doc available for this assembly
}
Defensive patterns

Strategy: try-catch

Validate before calling

var provider = new XmlDocumentationProvider(fileName); // no safe pre-check; the redirect target is resolved internally
// At the call site, simply tolerate absence:
XmlDocumentationProvider TryLoad(string f)
{
    try { return new XmlDocumentationProvider(f); }
    catch (XmlException) { return null; }
    catch (IOException) { return null; }
}

Try / catch

try { provider = new XmlDocumentationProvider(fileName); }
catch (XmlException ex) { logger.Warn($"XML doc unavailable for {fileName}: {ex.Message}"); provider = null; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.


AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13). Data as JSON: /api/errors/40a51d7b365bb2b8. Report an issue: GitHub.