Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host file not found #4

Open
qadeemakhtar opened this issue Apr 3, 2017 · 2 comments
Open

Host file not found #4

qadeemakhtar opened this issue Apr 3, 2017 · 2 comments

Comments

@qadeemakhtar
Copy link

image
I am facing this exception on some user side @fschwiet please help

@fschwiet
Copy link
Owner

fschwiet commented Apr 3, 2017

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.

@lextm
Copy link

lextm commented Jan 26, 2020

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants