Code being stepped over, not excuted

J

Jason

Hello

I've got a function in which I'm going to pass in a string which is a folder
path, and I want to get the size of that folder. When I step through the
code, the path I pass in is correct, however the compiler vc2005 never
executes the code in the if statements. If I watch my local window, i never
see the local variables, any ideas????


public void GetfolderProperties(string path)

{

if (Directory.Exists(path)) // the compiler executes this statement

{

DirectoryInfo dir = new DirectoryInfo(path); // the compiler dosen't
executes this statement

FileSystemInfo[] FSInfo = dir.GetFileSystemInfos(); // the compiler dosen't
executes this statement

}

}
 
J

John Vottero

Jason said:
Hello

I've got a function in which I'm going to pass in a string which is a
folder path, and I want to get the size of that folder. When I step
through the code, the path I pass in is correct, however the compiler
vc2005 never executes the code in the if statements. If I watch my local
window, i never see the local variables, any ideas????

Directory.Exists() works. When it returns false, the the directory does not
exist.

Is it an absolute or relative path? Is it a network path?
public void GetfolderProperties(string path)

{

if (Directory.Exists(path)) // the compiler executes this statement

{

DirectoryInfo dir = new DirectoryInfo(path); // the compiler dosen't
executes this statement

FileSystemInfo[] FSInfo = dir.GetFileSystemInfos(); // the compiler
dosen't executes this statement

}

}
 
F

Family Tree Mike

Jason said:
Hello

I've got a function in which I'm going to pass in a string which is a folder
path, and I want to get the size of that folder. When I step through the
code, the path I pass in is correct, however the compiler vc2005 never
executes the code in the if statements. If I watch my local window, i never
see the local variables, any ideas????


public void GetfolderProperties(string path)

{

if (Directory.Exists(path)) // the compiler executes this statement

{

DirectoryInfo dir = new DirectoryInfo(path); // the compiler dosen't
executes this statement

FileSystemInfo[] FSInfo = dir.GetFileSystemInfos(); // the compiler dosen't
executes this statement

}

}
There are two conditions that need to be satisfied for
Directory.Exists(). The directory must exist, and you must have
permission to read the directory.
 
J

Jason

I'm able to get into the if statement so it is true, in the debugger though
I do get those local variables. I stepped over the code, but I get nothing.
So when the debugger highlights the line DirectoryInfo dir = new
DirectoryInfo(path); I step into, but the variable dir is nothing, it never
appear in the local variable window



Family Tree Mike said:
Jason said:
Hello

I've got a function in which I'm going to pass in a string which is a
folder path, and I want to get the size of that folder. When I step
through the code, the path I pass in is correct, however the compiler
vc2005 never executes the code in the if statements. If I watch my local
window, i never see the local variables, any ideas????


public void GetfolderProperties(string path)

{

if (Directory.Exists(path)) // the compiler executes this statement

{

DirectoryInfo dir = new DirectoryInfo(path); // the compiler dosen't
executes this statement

FileSystemInfo[] FSInfo = dir.GetFileSystemInfos(); // the compiler
dosen't executes this statement

}

}
There are two conditions that need to be satisfied for Directory.Exists().
The directory must exist, and you must have permission to read the
directory.
 
D

DarekD

Could it be related to code optimization? Occasionally I'd run into
situation like yours, and simply using the object with Trace.WriteLine would
make it not being excluded.

Darek
 
J

John Vottero

Jason said:
I'm able to get into the if statement so it is true, in the debugger
though I do get those local variables. I stepped over the code, but I get
nothing.
So when the debugger highlights the line DirectoryInfo dir = new
DirectoryInfo(path); I step into, but the variable dir is nothing, it
never appear in the local variable window

Does the program throw a null reference exception when the FileSystemInfo...
line executes?

Are you sure that the .pdb file matches the executing code? If you delete
the .pdb file, is it recreated the next time you start the debugger?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top