File.Exists() returns false, but not in debug
Posted
by
Tor Haugen
on Stack Overflow
See other posts from Stack Overflow
or by Tor Haugen
Published on 2010-03-07T19:16:49Z
Indexed on
2012/09/03
15:38 UTC
Read the original article
Hit count: 194
I'm being completely confused here folks,
My code throws an exception because File.Exists() returns false
public override sealed TCargo ReadFile(string fileName)
{
if (!File.Exists(fileName))
{
throw new ArgumentException("Provided file name does not exist", "fileName");
}
Visual studio breaks at the throw statement, and I immediately check the value of File.Exists(fileName)
in the immediate window. It returns true
. When I drag the breakpoint back up to the if statement and execute it again, it throws again.
fileName is an absolute path to a file. I'm not creating the file, nor writing to it (it's there all along). If I paste the path into the open dialog in Notepad, it reads the file without problems.
The code is executing in a background worker. It's the only complicating factor I can think of. I am positive the file has not been opened already, either in the worker thread or elsewhere.
What's going on here?
© Stack Overflow or respective owner