System.IO Problem?

Hi all,

I’ve copied the first example from [url]GHI Electronics – Where Hardware Meets Software
in a solution and have the following problem, see image.

See post two and tree too.

This is the program:

using System;
using System.IO;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.FEZ;

namespace FEZ_Domino_SD_Application2
{
    public class Program
    {
        public static void Main()
        {
            // ...
            // 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();
        }

    }
}

Then I have entered the second example:

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

namespace FEZ_Domino_SD_Application3
{
    public class Program
    {
        public static void Main()
        {
            // ... check if SD is inserted

            // 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 NETMF
            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
            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);
            FileHandle.Close();

            // if we need to unmount
            sdPS.UnmountFileSystem();

            // ...
            Thread.Sleep(Timeout.Infinite);
        }

    }
}

System.IO.dll?

Y’re fast Gus.

Of course my first thought:
Repair the .NetMF sdk and of course the GHI sdk.

No result. Then I’ve deleted both sdks and reinstalled them in the right order.

No succes.

Some ideas???

Cu Wim.

There seems to be no System.IO.dll.

According to [url]Microsoft Learn: Build skills that open doors in your career the FileStream class is in mscorlib.dll.

But that information doesn’t help either.

Waiting for the golden tip.
And yes it is W7-64 bit.

Ce Wim.

Have you checked what references are used in this project on your PC C:\Users---------\Documents\Microsoft .NET Micro Framework 4.1\Samples\FileSystem

You will see the answer there :slight_smile: Microsoft.SPOT.IO maybe?

It is in System.IO.dll (documentation is wrong). I have just opened it in Reflector to verify. See image below

@ Gus,
If you enlarge the pic under my first two posts then you find Microsoft.SPOT.IO in the reference tables.
So thas is not the reason.
By the way I havenot got that folder that you mention, not in “all user” either.
I followed the standard information while installing VS2010Express and VS2010Prof.

@ Architect,
Reflector? I searched for that. Is it an extra debugger on top of the VS2010 one?
Or do you need Refelctor because you use antocher development system then VS2010.
And yes system.io.dll is at the right place. Ducumentation must be wrong.

I hope someone has an idea to solve this.

Cu Wim.

You have to add System.IO.dll to your references. I don’t see it in the pics you have posted.

Reflector is a .net “disassembler” - very handy tool that allows you to look inside compiled assemblies. If code is not obfuscated it will try it best to turn IL back into C#/VB.NET and other managed languages that it supports.

This is one of the must have tools for any .Net developer.

That is it. Gus mentioned it as well on his first anwer, but I was too busy thinking that FileStrem is in mscorlib.

Thanks, for the tip. This must have come across many of us.

Cu, Wim.

P.S. Maybe a good idea to mention this in the Wiki?

I echo the observation and complaint - I had a dickens of a time tonite (wasted over an hour of very precious time) chasing down a really basic item that needs to be clearly documented and isn’t.

Just some basic engineering principles - if you’re going to share code, then tell everyone about the #includes! (using’s in c#) and mention what References to load/add for the example code to work.

The problem is that there are several differences between .NET MF and original recipe .NET that unless someone documents things carefully in these examples, you spend needless hours chasing articles of undocumented minutia.

@ Wim: You can also view using VS 2010 Prof. by clicking on the Class View tab under the Solution Explorer window on the right side of the screen. If You open references, click on Class View; VS 2010 has reflector built-in.

while it would be nice to have the necessary references included as comments within a program, it is easy to find the necessary information in the sdk documentation.