简体   繁体   English

Xamarin.Forms json 文件流读取器 NullException 错误

[英]Xamarin.Forms json file stream reader NullException error

System.ArgumentNullException: 'Value cannot be null. System.ArgumentNullException: '值不能为空。 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.我从 GitHub 复制了代码和 json 文件。

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. Json 文件放置正确。 I also tried some different methods for reading json file but as you can see with no results.我还尝试了一些不同的方法来读取 json 文件,但正如您所看到的,没有结果。

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.如果确保您拥有的资源是嵌入式资源,请确保您的异常在 GetManifestResourceStream 中抛出,请参阅链接以获取更多信息。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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