简体   繁体   中英

Xamarin.Forms json file stream reader NullException error

System.ArgumentNullException: 'Value cannot be null. Parameter name: stream'

This is the error. Have been researching some information for a while now but can not find an answer. I copied code and json File from GitHub.

Code:

void AddMapStyle()
        {
            var assembly = typeof(PinMap).GetTypeInfo().Assembly;
            var stream = assembly.GetManifestResourceStream($"PcgDelivery.MapStyle.json");
            string styleFile;
            using (var reader = new System.IO.StreamReader(stream))
            {
                styleFile = reader.ReadToEnd();
            }

            map.MapStyle = MapStyle.FromJson(styleFile);
        }

Is there something wrong with code or what? Json file is placed correctly. I also tried some different methods for reading json file but as you can see with no results.

Make sure your exception is being throw in GetManifestResourceStream if it is make sure the resource you have is an embedded resource see link for more info.

https://adrianmejia.com/cs-getmanifestresourcestream-gotcha/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM