使用Windows.Data.Json的C#VS2017 IStringable Unreferenced Exception

前端之家收集整理的这篇文章主要介绍了使用Windows.Data.Json的C#VS2017 IStringable Unreferenced Exception前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我要直接进去.

我正在使用Windows.Data.Json转换并使用Web服务中的一些JSON.我知道关于Newtonsoft.Json.Net,以及其他一些等等.是的,我特别试图使用Windows.Data.Json,出于公司和依赖的原因.

该应用程序有3个主要部分/组件.

> UWP Win 10应用程序 – 主要应用程序
> MVC Web项目 – 应用程序的Web服务
>可移植类库 – 用于两者之间的共享类

我遇到的问题是,当我在MVC Web项目或PCL中使用JsonObject时,我收到错误

The type ‘IStringable’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘Windows.Foundation.FoundationContract,Version=2.0.0.0,Culture=neutral,PublicKeyToken=null,ContentType=WindowsRuntime’.

这个错误出现在我使用JsonObject的任何地方,但是,不在UWP应用程序项目中.

例如

//Convert string to json object
var apiJsonObj = JsonObject.Parse(jsonString);

cc.Type = apiJsonObj["TYPE"].ToString();

我在网上搜索过,找不到有关Windows.Data.Json和IStringable的任何有用信息,除此之外:
https://docs.microsoft.com/en-us/uwp/api/windows.foundation.istringable

我的项目没有在“添加引用”对话框中列出的Windows.Foundation.FoundationContract,我在我正在使用的UWP应用程序中找不到对它的任何引用,也没有任何其他有用的信息.

UWP应用程序和MVC Web应用程序使用相同的代码行来解释JsonObject. UWP应用程序正常运行. MVC Web应用程序给出了上述错误.

我想知道是否有其他人成功使用Windows.Data.Json,可能遇到过这个问题,并且修复了吗?

应用程序必须尽可能小且独立,因此引用数量少,并且无法使用Json.Net等.

解决方法

This error is showing up everywhere I use the JsonObject,however,NOT in the UWP app project.

Windows.Foundation.FoundationContract程序集是platform specific.您无法在便携式库中使用它.虽然你可以通过选择winmd文件在下面的文件夹中添加引用,但它会抛出编译错误.

C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\2.0.0.0\Windows.Foundation.FoundationContract.winmd

目前,Json.NET已经支持可移植库,您可以使用它来解析json.您可以选择不会导致复杂程序集依赖性的Json.NET.

猜你在找的Windows相关文章