2013-01-23 59 views
1

我在與讀取包含採用Windows Phone 8和MonoGame框架我的水平的信息簡單的文本文件有問題。文本文件閱讀的Windows Phone 8和MonoGame

我的文件閱讀功能的工作原理只是一個普通的Windows Phone 8的項目很好,但是當我嘗試使用它monogame項目它給我,當它試圖創建新的FileStream此錯誤:

「例外類型「System.MethodAccessException」發生在 mscorlib.ni.dll但在用戶代碼」

這是我的文件閱讀功能沒有處理

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); 
} 

我的方法是完全錯誤的還是有人有想法,爲什麼這不工作?我試圖從我的項目文件中讀取文件。

+0

這幾乎肯定不是你的問題,但你似乎已經在這裏重新實現File.ReadAllText。此外,您忘記處理該流。 – Trillian

+0

此外,當拋出異常(調試時)時,您應該可以單擊「查看詳細信息...」並查看關於異常的更多特定信息。也許嘗試併發布結果? – lhan

回答