Search code examples
xmliis

FileNotFound when reading the IIS applicationHost.config file


Why I get FileNotFound using this code? if I move the applicationHost.config file to another directory such as c:\temp it will read just fine.

const string IIS_CONFIG_FILE = 
@"C:\Windows\System32\inetsrv\config\applicationHost.config";
string xml = File.ReadAllText(IIS_CONFIG_FILE);
XDocument doc = XDocument.Load(new StringReader(xml));

It has to do with the directory because I can't even open a simple Test.xml file there. I used Process Monitor from SysInternals but nothing is traced. Very weird.

Thank you Max


Solution

  • If you try to read such 64 bit only file in a 32 bit application, then Windows leads you to the equivalent WOW64 file path, which indeed does not exist.