簡體   English   中英

Xamarin.Forms json 文件流讀取器 NullException 錯誤

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

System.ArgumentNullException: '值不能為空。 參數名稱:流'

這是錯誤。 已經研究了一段時間的一些信息,但找不到答案。 我從 GitHub 復制了代碼和 json 文件。

代碼:

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);
        }

代碼有問題還是什么? Json 文件放置正確。 我還嘗試了一些不同的方法來讀取 json 文件,但正如您所看到的,沒有結果。

如果確保您擁有的資源是嵌入式資源,請確保您的異常在 GetManifestResourceStream 中拋出,請參閱鏈接以獲取更多信息。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM