System.IO.File.Exists () another answer from x86 and x64 applications

I am using Visual Studio 2012 with the installation of Update 3. I am using C # to target the .NET framework 4.5.

I have a method that starts as follows:

public void Open(System.String filePath) { if (!System.IO.File.Exists(filePath)) throw new FileNotFoundException(. . .); . . . } 

The value of the filePath parameter is filePath follows:

"C:\\Users\\Jonathan.DeCarlo\\Source\\Repos\\PoliticalClassifier\\src\\PoliticalClassifier.DataSource.Tests\\TestFiles\\Social_Economic_DataMicro.xlsx"

This path really exists on my machine. This application is compiled as "Any processor." I run it on a computer with Windows 7 x64 installed. If I allow applicationactin to work as an x64 process, then a FileNotFoundException is FileNotFoundException even if the file exists. If I make the application run as an x86 process, then the exception is NOT thrown (which should be the case).

Why System.IO.File.Exists(filePath) return a different result when the application runs as an x64 process and not an x86 process?

+6
source share
1 answer

Thanks for all the comments. I tried several of them and found that I could not reproduce the problem for any file other than the one I pointed out with my source code. Over the past couple of days, I began to see my hard drive fail. Having received a new hard drive, configured it again and running the above program, I no longer see this problem. I cannot be 100% sure of this, but I'm going to assume that the file I was trying to open was corrupted by a failover disk. I apologize for chasing the wild geese.

+4
source

Source: https://habr.com/ru/post/949041/


All Articles