简体   繁体   中英

MethodAccessException for StreamReader in XNA Windows Phone App

I am trying to create a map and I'm starting off by loading a text file into a StreamReader in the LoadContent method. However I'm getting a MethodAccessException: security transparent method cannot access security critical method.

StreamReader reader;

protected void LoadContent()
{ 
   reader = new StreamReader("map.txt");
}

However this same code works in a regular Windows Phone 8 app. It has nothing to do with the fact that it is loaded in a protected method. Already checked that. Also the text file is available in the project folder of the XNA game.

If you need any more info please let me know. Thanks in advance.

I didn't completely figure out the reason (it seems to be a problem with XNA Windows Phone apps) but I did figure out a work around. Use a TitleContainer to open a stream and then load this into the constructor of the StreamReader as shown below.

StreamReader reader;

protected void LoadContent()
{ 
  var stream = TitleContainer.OpenStream("map.txt");
  reader = new StreamReader(stream);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM