I was trying to load an embedded resource into a Silverlight DLL using this code:
System.Reflection.Assembly asm = Assembly.GetExecutingAssembly();
System.IO.Stream xmlStream = asm.GetManifestResourceStream("Namespace.Filename.xml");
XDocument xDoc = XDocument.Load(xmlStream);
However, the xmlStream was null and hence an exception. I had mistyped the "Namespace.Filename.xml" part of the code but couldn't see what part I'd mistyped. To fix this I changed the code to this:
System.Reflection.Assembly asm = Assembly.GetExecutingAssembly();
System.IO.Stream xmlStream = asm.GetManifestResourceStream("Namespace.Filename.xml");
string[] names = asm.GetManifestResourceNames();
XDocument xDoc = XDocument.Load(xmlStream);
and put a break point on the last line and inspected the names array to find the correct name. It was late at night and I was tired so a copy/paste finally resolved to the correct name.
No comments:
Post a Comment