System.IO.File.Exists(@“C:\Windows\System32\SnippingTool.exe”) returns false

前端 未结 2 1653
你的背包
你的背包 2020-12-20 23:27

So I am working on a simple .NET program for work and hit a bit of a weird roadblock I can\'t figure out. The application makes use of a configuration file which adds appli

相关标签:
2条回答
  • 2020-12-20 23:50

    That's a feature of 64 bit Windows.

    In x64 you have two folders with system files: system32 and SysWOW64.

    If you put anything in system32, it will be seen by all 64 bit applications. SysWOW64 is there for compatibility reasons - anything put there will be visible by 32 bit (sic!) apps.

    So as far as .NET is concerned, the file does not exist. It works for notepad, because notepad.exe is present in both of those directories.

    You can test this behaviour. Create a text file in one of the directories, but not the other and check for its existence. Then change your project configuration (right click on solution -> Configuration Manager) between x86 and x64 and enjoy the result.

    0 讨论(0)
  • 2020-12-21 00:03

    I have a crazy bug relate to this topic. Thank ya23.

    In my case, just changing project Properties > Build > uncheck Prefer 32-bit

    0 讨论(0)
提交回复
热议问题