Assembly.GetExecutingAssembly().GetManifestResourceStream("XMLController.xml") not reading file

I am trying to figure out some code that I am maintaining. Basically there is a line of code which appears to open an xml file and store it into a Stream object "s". When I step into the code the variable s come back with a value of "Nothing". The code I am talking about is at line 10 below. Can someone help me out here?

also, I am not sure if the file XMLController is not being found when the code executes. I have tried these two different things but I still am getting a value of "Nothing" when I trace past line 10.
A  Placed the file XMLController.xml into the root folder of my laptop C:\    
B  I have tried specifying the path to the file : GetManifestResourceStream("C:\MyProject\XMLController.xml")


9
10  Dim s As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("XMLController.xml")
11
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi  brgdotnet;

The method Assembly.GetExecutingAssembly().GetManifestResourceStream(String) is an embedded resource and in your case is an embedded XML file, so it is not on the file system but embedded into the application. Is this file located in the project you are working on?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brgdotnetcontractorAuthor Commented:
Hello Sir,

I can see the file in a folder "XMLHandler" which contains many XML files, and also contains the XMLController.xml file. I targeted that folder in the path, yet it still comes back as nothing when I trace into the code.

Dim s As Stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("C:\MyProject\XMLHandler \XMLController.xml")

Sir, I am not sure what you mean by embedded resource. That file does have data, and I can see it located the the XMLHandler folder.
0
käµfm³d 👽Commented:
I always forget how this works exactly, but the name of your resource get prepended with the namespace (I believe) when it's added as a resource. You'll need the exact name in order to extract it. You can quickly figure out what the name is by using the following code within the Immediate Window:

?Assembly.GetExecutingAssembly().GetManifestResourceNames()

Put a breakpoint on the line you show above, and then use this command to see the resources you have embedded. Whichever one matches the XML file is the one you should use within your code.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Fernando SotoRetiredCommented:
OK, in order to have a file as part of the resource manifest of your application you need to do the following.

The XML file needs to be imported into the project. To do that go to the Solution Explorer window and right click on the project name, that is the second line down in the first figure below.

Then click on Add -> Existing Item. A new window will open. Navigate to the XML file to be embedded into the application, select it and click on the Add button. That file will now show up in the solution explorser.

Now right click on the file you just added to the project and select Properties. The Properties window should now be opened. the top option called Build Action needs to be changed to Embedded Resource as shown in figure 2 below. That file now is an embedded resource of the application.

Now you can get access by using your statement,

Dim s As Stream = Me.GetType().Assembly.GetManifestResourceStream(ResourceName)

Where RecourceName is made up of a couple of parts The application namespace and the name of the XML file name. All the characters in that string needs to be in the same case as the namespace and file. For example if the application namespace is WindowsApplication1 and the file name is XMLController.xml then the ResourceName will be

"WindowsApplication1.XMLController.xml"
Screen-Shot-2015-07-15-at-8.46.42-PM.png
Screen-Shot-2015-07-15-at-8.47.25-PM.png
0
Fernando SotoRetiredCommented:
By the way if for some reason you can't figure out the ResourceName to use place this line of code in the application and look at the array of strings it returns int will be in that list of names.

Dim names As String() = Me.GetType().Assembly.GetManifestResourceNames()

Open in new window

0
käµfm³d 👽Commented:
Like I said...?
0
brgdotnetcontractorAuthor Commented:
You guys are geniuses. Thank you. I will give both solutions a try and award the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.