Mohamad Mahmoud Darwish
Mohamad Mahmoud Darwish

Reputation: 4173

Xamarin.Forms Can not Read Text file from Resources Returned Null

I am using Xamarin.Forms, and I am trying to read text file from Resources, Code Below Returned Null value when trying to fetch text file.

 var assembly = typeof(BookPage).GetTypeInfo().Assembly;
 Stream stream = assembly.GetManifestResourceStream("AboutResources.txt");

//assembly here return null value, I can not find Text Resources

My Code under the following Class Inherited From ContentPage On PLC Project

 public class BookPage : ContentPage

enter image description here

Upvotes: 1

Views: 5165

Answers (2)

Mohamad Mahmoud Darwish
Mohamad Mahmoud Darwish

Reputation: 4173

The following steps working fine for me:

1-First of all I added resource text file to same project

2-The file path must be like "Your Project name.your custom folder.filename".

var fileName = "MySampleProject.XMLData.rawxmldata.xml".

3-Make sure that Build Action is EmbeddedResource.

Upvotes: 5

Carbine
Carbine

Reputation: 7903

//First get the list of all resources available for debugging purpose
assembly.GetManifestResourceNames()

This will list all the (fully qualified names) of all resources embedded in the assembly your code is written in.

Link: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmanifestresourcenames(v=vs.110).aspx

Check if it has "AboutResources.txt" that you are expecting. Check if you have incorrectly embedded the resource file, it will not show up in the list returned by the call to GetManifestResourceNames(). Make sure you you match the case of the name.

Upvotes: 5

Related Questions