I have a Silverlight 4 / C# project I’m working on in Visual Studio. I made an XML data file by right clicking on the project >> Add New Item >> Xml File. I then try to open the file:
StreamReader streamReader = new StreamReader("data.xml");
However, this gives a security exception. How can I get around this, or grant the necessary permissions?
That constructor of StreamReader is expecting a file path into the local file system, which is only available out of browser with elevated trust.
Instead you should be using
Application.GetResourceStream:-However I expect you really just want this in an
XDocument, you bypass this StreamReader stage:-BTW, I personally would leave the XML as Content in the Xap rather than embedding it in the assembly.