0

I am trying to read countries.json from an EmbeddedResource but the GetManifestResourceStream always return null, what I missed?

I tried to set countries.json Build Action property to Embedded resource

    var assembly = Assembly.GetEntryAssembly();
    var resourceStream = assembly.GetManifestResourceStream("EmbeddedResource.Resources.countries.json");  // THIS ALWAYS RETURNS NULL 


    using (var reader = new StreamReader(resourceStream, Encoding.UTF8))
    {
        string _json =  await reader.ReadToEndAsync();
        JArray _ja_countries = JArray.Parse(_json);
        for (int _i = 0; _i < _ja_countries.Count; _i++)
        {
            string _code = (string)_ja_countries[_i]["country-code"];
            string _name = (string)_ja_countries[_i]["name"];
            string _alpha3 = (string)_ja_countries[_i]["alpha-3"];

            _lcountry.Add(new Models.Country
            {
                code = _code,
                name = _name,
                alpha3 = _alpha3
            });
         }
     }
Donald
  • 551
  • 2
  • 6
  • 22
  • Does the answer to [this question](https://stackoverflow.com/questions/10726857/why-does-getmanifestresourcestream-returns-null-while-the-resource-name-exists-w) fix your problem? – ProgrammingLlama Jul 29 '19 at 02:27
  • 1
    I suggest: 1. Use debugger to check if `GetEntryAssembly` returns the assembly you store embedded resource. 2. Use `Assembly.GetManifestResourceNames` to check name of all embedded resource. – Leisen Chang Jul 29 '19 at 02:44
  • Possible duplicate of [Why does GetManifestResourceStream returns null while the resource name exists when calling GetManifestResourceNames?](https://stackoverflow.com/questions/10726857/why-does-getmanifestresourcestream-returns-null-while-the-resource-name-exists-w) – vasily.sib Jul 29 '19 at 03:42

0 Answers0