0

I run my app as administrator. However, I get an exception here

var myFileVersionInfo = FileVersionInfo.GetVersionInfo(fileName);

when filename is "C:\Windows\System32\WFS.exe".

The file does really exist. What should I do to fix it?

Any help will be appreciated!

Eva Leigh
  • 51
  • 1
  • 9
  • Which exception? File not found? – Antoine V Jul 05 '18 at 09:51
  • https://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx – andy Jul 05 '18 at 09:56
  • [WoW](https://stackoverflow.com/q/912726/1132334) - that is, 64 bit vs. 32 bit system directory mapping? – Cee McSharpface Jul 05 '18 at 09:58
  • I dont want to be rude. But there is once I saw a newbie c# coder write \ in string directly without using \\ or @. – scegg Jul 05 '18 at 10:22
  • @ThierryV yes, file not found – Eva Leigh Jul 05 '18 at 10:25
  • @andy this method also returns false, i've already checked – Eva Leigh Jul 05 '18 at 10:26
  • @scegg actually, the filename comes from foreach cycle. so it contains \\. if your c# skills were better, you knew, that program with this line [FileVersionInfo.GetVersionInfo("C:\Windows\System32\WFS.exe")] would never run. Cause it is a syntax error. And i have an exception, not an error. – Eva Leigh Jul 05 '18 at 10:32
  • @EvaLeigh then you may need to post more related code. Or, try to create a new and simple app with the same arch you selected, write only such a line to verify the file is really there. Sometimes, mapping will mask something from the reality. – scegg Jul 05 '18 at 10:40
  • 2
    Project > Properties > Build tab, untick the "Prefer 32-bit" checkbox. You don't prefer it. Or use c:\windows\sysnative\wfs.exe, you don't really prefer that either. Everybody needs to learn about the [File System Redirector](https://learn.microsoft.com/en-us/windows/desktop/winprog64/file-system-redirector). – Hans Passant Jul 05 '18 at 10:43
  • This is quite an interesting issue. Trying it myself in LinqPad, I can confirm the file exists but this throws a FileNotFoundException. What's also interesting, looking at the folder in explorer I tried the previous file WFhC.dll and it worked. Then started using random files from the folder: wextract.exe works, wifitask.exe doesn't... – Stevo Jul 05 '18 at 10:43
  • As @HansPassant says, looks like it's file system redirection: https://social.technet.microsoft.com/wiki/contents/articles/19256.avoid-file-system-redirection-in-visual-studio-2012.aspx – Stevo Jul 05 '18 at 10:51
  • Retracted my answer after a ticking off :D. As @HansPassant says 'sysnative' instead of 'system32' works. – Stevo Jul 05 '18 at 11:19
  • Having `System32` hold 64-bit dlls, and using redirection for the 32-bit ones, instead of having a `System32`, for x86, and a `System64` for x64 ones isn't exactly intuitive. I'm sure it was absolutely the best option for compatibility reasons, but this kind of thing drives me nuts. – Bradley Uffner Jul 05 '18 at 11:25
  • @HansPassant thanks a lot, it worked for me! – Eva Leigh Jul 05 '18 at 11:35
  • @SteveJ i also tried to use Wow64DisableWow64FsRedirection and it worked as well as approach offered by HansPassant. however, as it's better to avoid redirection, i've chosen the second approach. anyway, thanks a lot! – Eva Leigh Jul 05 '18 at 11:39
  • @EvaLeigh whatever you chose, write an answer below and accept it. – Lex Li Jul 05 '18 at 16:23

1 Answers1

0

The solution was to untick "Prefer 32-bit" (Project > Properties > Build tab).

Eva Leigh
  • 51
  • 1
  • 9