I'm trying to read in a JSON file from an embedded resource. I've tried looking online but most questions are about .txt files that aren't helping.
I've already tried making the json file an embedded resource but that hasn't helped either.
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "MyLibrary.Properties.Resources.MyJson.json";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string jsonFile = reader.ReadToEnd(); //Make string equal to full file
}
When this code is run, I get the following error: System.ArgumentNullException: 'Value cannot be null. Parameter name: stream'
This was fixed by changing
var resourceName = "MyLibrary.Properties.Resources.MyJson.json";
to this:
var resourceName = "MyLibrary.Resources.MyJson.json";
Having "Properties" in the resourceName is incorrect it seems.