PSHostsFile
PSHostsFile copied to clipboard
Host file not found
I am facing this exception on some user side @fschwiet please help
Does the file exist, or is it in another location?
Here is the code that expects to find the file:
public static string GetHostsPath()
{
var systemPath = Environment.GetEnvironmentVariable("SystemRoot");
var hostsPath = Path.Combine(systemPath, "system32\\drivers\\etc\\hosts");
if (!File.Exists(hostsPath))
throw new FileNotFoundException("Hosts file not found at expected location.");
return hostsPath;
}
If the file does not exist, then I suggest creating it. I don't know your platform, so I suppose you'll need to check that the OS uses the file at that location.
@fschwiet WOW64 redirection can lead a 32 bit application to report such exceptions on a Windows x64 machine. You should modify your library to better work that scenario,
https://stackoverflow.com/questions/25908033/how-to-get-64bit-system-folder-in-a-32bit-application