Resolved Embedded Resource XML File not recognized

pgm575

Member
Joined
Jul 16, 2010
Messages
12
Programming Experience
Beginner
So in my VBE2010 project I have an XML file containing some values I need ("UnitVals.xml"). When I accessed this before, I was simply placing it in the project folder, finding the local path from System, and reading the file into an XMLDocument object.

I didn't really like having to concern myself with the location of the file, however, so I set its "Build Action" property to "Embedded Resource." There are numerous examples of code on the net as to how to use this, which I have written into my code as follows-

VB.NET:
Dim xmlDoc As New Xml.XmlDocument
Dim s As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("UnitVals.xml")
Dim reader As New System.IO.StreamReader(s)

xmlDoc.LoadXml(reader.ReadToEnd)

Unfortunately, my Stream keeps returning as Nothing. Does anyone know why this might be?
 
Last edited:
So the solution here for anyone who happens upon this is that I did not reference my namespace in calling the XML file. The line that read
VB.NET:
asm.GetManifestResourceStream("UnitVals.xml")
should have read
VB.NET:
asm.GetManifestResourceStream("EngineeringCenter.UnitVals.xml")
as my project namespace is "EngineeringCenter."
 
A simpler way to use application resources is the project Resources page and the My.Resources object. Here you can for example paste in the xml file and in code access it like this:
xmlDoc.LoadXml(My.Resources.UnitVals)
 

Latest posts

Back
Top