Textfile Reading, Windows Phone 8 and MonoGame

I'm having a problem with reading simple text file containing my level information using Windows Phone 8 and MonoGame framework.

my file reading function works just fine with a normal Windows Phone 8 project but when I try to use it on monogame project it gives me this error when its trying to create new FileStream:

"An exception of type 'System.MethodAccessException' occurred in mscorlib.ni.dll but was not handled in user code"

this is my file reading function

private string readFile(string fileName)
{
    FileStream fs = new FileStream(fileName, FileMode.Open);

    byte[] bytes = new byte[fs.Length];
    int numBytesToRead = (int)fs.Length;
    int numBytesRead = 0;
    while (numBytesToRead > 0)
    {
        int n = fs.Read(bytes, numBytesRead, numBytesToRead);

        if (n == 0)
        {
            break;
        }

        numBytesToRead -= n;
        numBytesRead += n;
    }

    numBytesToRead = bytes.Length;
    return System.Text.UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length);
}

Is my approach complitely wrong or does anyone have ideas why this isnt working? I'm trying to read the file from my project files.

Answers


Since Windows Phone apps are sandboxed, you would typically use the Isolated Storage classes for saving files, and not go directly to System.IO. But since you mention level information (compiled into your app?), perhaps the following link will help:

How do I embed and read a text file ina WP7 app?


Need Your Help

Using rails draper gem with angularjs and json

ruby-on-rails json angularjs draper

so, I have seen people dancing around this topic, but I can't find the answer. I just installed the 'draper' gem with rails. It's great, but I want to be able to use it with angularjs. Is there ...

Installing PIL on Snow Leopard

python python-imaging-library

Hey, i have a problem installing PIL on Snow.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.