I'm trying to read PCL content file that I'm adding with the resource. the ideal use case for this is a REST service mock where I want to host a few json files for testing the Network services. I want to be able to read these json files as an alternative if the server is not available so what do I do to be able to achieve this?
both the json files and the NetworkService class are within the PCL. assume no other solution is relevant
this is what I tried
This is the part of the NetworkService fallback code
var uri = new Uri("ms-appx:///mock/users/" + UserID + "/GET.json");
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
I get a System.IO.FileNotFoundException when I try to run this code. any ideas what I could be doing wrong? I tried the EmbeddedResource approach and that didn't work either.
This is an EmbeddedResource method that kinda workedfor the moment, I will upvote/mark a better answer involving Build Action > Content as that is a cleaner approach to handling this problem. the solution is presented in one of the answers here
// the below approach is essential to getting the right assembly
var assembly = typeof(TestClass).GetTypeInfo().Assembly;
// Use this help aid to figure out what the actual manifest resource name is.
// can be removed later
string[] resources = assembly.GetManifestResourceNames();
// Once you figure out the name from the string array above, pass it in as the argument here.
// . replaces /
Stream stream = assembly.GetManifestResourceStream("TestMockJson.Mock.TestFile.Json");
var sr = new StreamReader(stream);
return sr.ReadToEnd();