I have a Silverlight application in which I am doing the following thing to load a XML file, and further to parse it.
I have set the Build Action to Embedded Resource, Copy to Output Directory.
The code that I am using is:
try
{
Xmlfile = XDocument.Load(Assembly.GetExecutingAssembly().GetManifestResourceStream("file.xml"));
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
Message that I receive as an exception:
Value cannot be null.
Parameter name: input
EDIT
I tried the following which works (in WPF), but gives problem in Silverlight:
Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + ".file.xml")
Error:
'System.Reflection.Assembly.GetName()' is inaccessible due to its protection level
You will need to prepend the name of your assembly and its subfolders, like this:
Sometimes it’s not clear exactly what the subfolder(s) should be. If that’s the case, just inspect the names directly using this: