The nine most terrifying words in the English language are, ‘I’m from the government and I’m here to help.
Ronald Reagan
40th president of US (1911 – 2004)
It never fails to surprise me when software does not do something that it is smart enough to do – but doesn’t. In the midst of writing some code to enumerate the folders on the CF card for the FEZ Panda II, Visual Studio 2010 was kind enough to give me the following errors.
Here is the code
When I looked up the reference on MSDN to discover that it was in the System.IO namespace and the mscorelib assembly. However VS still generated the error. Turns out that I needed to add the SystemIO reference. As the frustration faded, I began forming theories about why didn’t VS automatically add the Using statement with the proper reference into the project. Realized that in theory I might be talking about another implementation. However, the error should have at least offered a recommendation for the best default implement.
using System; using System.IO; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.IO; using Microsoft.SPOT.Hardware; using GHIElectronics.NETMF.FEZ; using GHIElectronics.NETMF.IO; namespace DebugTest { public class Program { public static void Main() { // Blink board LED bool ledState = false; OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState); Debug.Print(Resources.GetString(Resources.StringResources.String1)); Debug.Print("Amazing!"); //--------------------------------------------------------------------------------------- // SD Card is inserted // Create a new storage device PersistentStorage sdPS = new PersistentStorage("SD"); // Mount the file system sdPS.MountFileSystem(); // Assume one storage device is available, access it through // Micro Framework and display available files and folders: Debug.Print("Getting files and folders:"); if (VolumeInfo.GetVolumes()[0].IsFormatted) { string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory; string[] files = Directory.GetFiles(rootDirectory); string[] folders = Directory.GetDirectories(rootDirectory); Debug.Print("Files available on " + rootDirectory + ":"); for (int i = 0; i < files.Length; i++) Debug.Print(files[i]); Debug.Print("Folders available on " + rootDirectory + ":"); for (int i = 0; i < folders.Length; i++) Debug.Print(folders[i]); } else { Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first."); } // Unmount sdPS.UnmountFileSystem(); //----------------------------------------------------------------------------------------------- while (true) { // Sleep for 500 milliseconds Thread.Sleep(500); // toggle LED state ledState = !ledState; led.Write(ledState); } } } }