Exception when handling files


I followed some discussions here about exceptions that occur when opening files and other uses.
I use micro sd of SanDisk 2GB.
I formated the card to FAT and then to FAT32 and in both cases I receive execptions.
I set a timeout of 3 seconds after the mount, before I start to deal with the card.
Nothing help.

What I do is:

I create a file and then I close it and get an exception:

Exception System.ObjectDisposedException - 0x00000000 (6)

System.IO.FileStream::get_Length [IP: 0009]

Uncaught exception

If I read an exsiting file I get the same exception when I close it, and if I try to read it again, the file handle is NULL.

Sample of my code:

static void Main() 
PersistentStorage sdPS = new PersistentStorage("SD"); 
//// Assume one storage device is available, access it through NETMF 
string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory; 
rootDirectory += "\\files\\"; 
FileStream FileHandle = new FileStream(rootDirectory + "hello.txt", FileMode.Create); 
//byte[] data = Encoding.UTF8.GetBytes("This string will go in the file!"); 
// write the data and close the file 
//FileHandle.Write(data, 0, data.Length); 


First, make sure you have updated to VS2010 and NETMF 4.1 (see downloads page)

Now try…still problems?

If so, make your code as small as possible and post the complete code her…all of it 100% so someone can try it for you.

I updated to VS2010 and NETMF 4.1 and so far everything looks good. :slight_smile: