Main Site Documentation

Stumbling and bumbling as I start



I am trying to get basic read/writes working on the SD card of the Domino. Hugely frustrating.

The first card I had won’t ork - won’t get recognized. Never got passed initializing the Persistent storage object (4gb Patriot - formated 9 ways till sunday.)

I have been copying/pasting/editing code from a ton of sources. I copied and merged the following from the beginners guide and it won’t work…any ideas?

It errors out on: FileHandle.Write(data, 0, data.Length.

I have tried this with and without the directroy sniffer. It does see and print the directories and files on the card. There is plenty of room on the card.

using System.Threading;
using System.Text;
using Microsoft.SPOT;
using System.IO;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;

namespace Test
    class Program
        public static void Main()

            PersistentStorage sdPS = new PersistentStorage("SD");

           Debug.Print("Getting files and folders:");
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
                string 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("Folders available on " + rootDirectory + ":");
                for (int i = 0; i < folders.Length; i++)
           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);


                Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");



Don’t be frustrated, we are here to help :slight_smile:

So you said it is failing on write? Then all work fine when you mount and read directories and what about reading files? What about read? Did you try to step in the code or you are just free running?

Now you also said the first card didn’t work! So how many cards have you tried? What maker and size?

Finally, did you try to format the card as FAT32 and as FAT16 on the PC then try? Also, did you try to format the card full, I mean not use “quick format”?


Will this code work?:

// Mount here.

using (StreamWriter sw = new StreamWriter(@ "\SD\newfile.txt", false))
using (StreamReader sr = new StreamReader(@ "\SD\newfile.txt"))
    Debug.Print("newfile.txt contents:");


I have 2 Cards: a PNY and a Patriot both are 4GB SDHC. I have been doing combinations of quick and full formats on FAT 16 and 32.

The PNY is working on reading the file system - and then failing on the writes. The Patriot can’t be mounted at all. even if it is formatted in FAT 16 or 32.

I just tried the streamwriter variation - and no luck there. (I can write to the card through Windows - although I have to use a separate reader as I can’t see the cards through the Domino).

I have been doing F5s and F11s…


option 1:
Can we borrow your cards for couple days? Or give me a link to where we can but the exact same card in USA so we can buy it and try it?

option 2:
Do you have electronics background? If so, try this one thing please…

Look at

You see C10 close to the SD connector? Add a capacitor on top of C10. Maybe a 47uF or whatever you have handy.

You can see where it is in schematics too
The plus side is towards the transistor if you are using polarized cap.

Did this fix your problem?


Also, please paste here the exception messages from the debug output window in visual studio.


I am happy to send the cards - where to?

I bought the Patriot in Frys a few days ago. The PNY was from newegg I think.

I will try the CAP in a bit…until then…


This is from the Patriot when it fails to mount:

The thread ‘’ (0x2) has exited with code 0 (0x0).
#### Exception System.Exception - 0xffffffff (1) ####
#### Message:
#### GHIElectronics.NETMF.IO.PersistentStorage::.ctor [IP: 0000] ####
#### Test.Program::Main [IP: 0007] ####
A first chance exception of type ‘System.Exception’ occurred in GHIElectronics.NETMF.IO.dll
An unhandled exception of type ‘System.Exception’ occurred in GHIElectronics.NETMF.IO.dll


This is from the PNY when it fails to write - you can see it reads and outputs the files and folders (the disk was empty):

The thread ‘’ (0x2) has exited with code 0 (0x0).
Getting files and folders:
Files available on \SD:
Folders available on \SD:
#### Exception System.IO.IOException - CLR_E_FILE_IO (1) ####
#### Message:
#### Microsoft.SPOT.IO.NativeFileStream::Write [IP: 0000] ####
#### System.IO.FileStream::Write [IP: 002a] ####
#### Test.Program::Main [IP: 00ba] ####
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


Please ship to GHI address to my attention please.

We will send them back to you with a gift :wink:


Will do.

BTW - I went to Best Buy and got a 2GB PNY SD card (not an sdhC) - and it works great.


Gus - I tried to send you the SD cards that did not work and they came back…

Can you look to see if I got the address right?


Address is 35555 not 3555 :slight_smile:


There are some people who had problems with SD card. It turned out that if you plug a power pack, it will work fine. Also, in a similar thread, a user connected a bigger capacitor on SD power, it worked fine too. You can try this before sending the cards.



I received a System.Exception when I created new PersistentSotorage

PersistentStorage sdPS = new PersistentStorage(“SD”);

catch (Exception ex)


Try examples from the book first:

The code in the book has been tested and is working.

As a side note when you post a code snippet please use “Code” button (the one with 1s and 0s). It is easier to read properly formatted and colored code. :wink: