I have the method below which is to open and close the SD Card, it’s called from a loop, on first method call I get the unhandled exception shown attached and the output window shows the message below, on all subsequent calls it works without any errors?? Why would this be, I’ve no idea.
OUTPUT WINDOW MESSAGE
–A first chance exception of type ‘System.IO.IOException’ occurred in Microsoft.SPOT.IO.dll
An unhandled exception of type ‘System.IO.IOException’ occurred in Microsoft.SPOT.IO.dll–
for (byte i = 0; i < 100; i++)
{
Debug.Print(i.ToString());
TestSDCard();
Thread.Sleep(100);
}
public static void TestSDCard()
{
var SdCard = new SDCard();
SdCard.Mount();
Thread.Sleep(100);
SdCard.Unmount();
SdCard.Dispose();
}
@ Mike - Thanks, can you direct me to the documentation you mention with regards to what should be done after a mount, the unhandled exception occurs after the method returns.
I received this same error while refactoring my project from 4.3.3.0 to 4.3.6.0 in VS 2013. I commented out all the SDCard stuff (class initialization, Mount(), Unmount()) and I still seem able to access the SD card.
if (Microsoft.SPOT.IO.VolumeInfo.GetVolumes()[0].IsFormatted)
{
string rtDirectory = Microsoft.SPOT.IO.VolumeInfo.GetVolumes()[0].RootDirectory;
System.IO.Directory.SetCurrentDirectory(rtDirectory);
string[] files = System.IO.Directory.GetFiles(rtDirectory);
string[] folders = System.IO.Directory.GetDirectories(rtDirectory);
Debug.Print("Files available on " + rtDirectory + ":");
for (int i = 0; i < files.Length; i++)
Debug.Print(files[i]);
Debug.Print("Folders available on " + rtDirectory + ":");
for (int i = 0; i < folders.Length; i++)
Debug.Print(folders[i]);
}
I might be wrong, maybe I am using the wrong API configuration, or it might be specific to my hardware. FEZ Cobra II.
@ DanW - Thanks, yes it seems to work nicely if I mount the SdCard only in the Init method, and comment out all other SdCard lines of code, for my application the SD Card will always be the same card, and will always be inserted