Json.NET在.NET 4下说“操作可能会使运行时不稳定”,但在.NET 3.
发布时间:2020-12-16 18:40:57 所属栏目:百科 来源:网络整理
导读:这段代码: namespace ConsoleApplication3{ class Program { static void Main(string[] args) { var client = new WebClient(); client.Headers.Add("User-Agent","Nobody"); var response = client.DownloadString(new Uri("http://www.hanselman.com/sma
这段代码:
namespace ConsoleApplication3 { class Program { static void Main(string[] args) { var client = new WebClient(); client.Headers.Add("User-Agent","Nobody"); var response = client.DownloadString(new Uri("http://www.hanselman.com/smallestdotnet/json.ashx")); var j = JsonConvert.DeserializeObject<SmallestDotNetThing>(response); } public class SmallestDotNetThing { public DotNetVersion latestVersion { get; set; } public List<DotNetVersion> allVersions { get; set; } public List<DotNetVersion> downloadableVersions { get; set; } } public class DotNetVersion { public int major { get; set; } public int minor { get; set; } public string profile { get; set; } public int? servicePack { get; set; } public string url { get; set; } } } } 在.NET 4下使用.NET 4版本的JSON.NET时,将在Deserialize上抛出异常“操作可能会破坏运行时的稳定性”. 但是,将目标切换到3.5(并将JSON.NET引用更改为3.5版本)效果很好.我正在使用NuGet的JSON.NET. 思考? 解决方法
.NET 4的运行时(参见
Karel Zikmunds answer和
.NET Security Blog条目)中的安全模型似乎发生了变化,它依赖于AllowPartiallyTrustedCallersAttribute.
Karel还发布了一些解决方案:
Stackoverflow上的另一个post,C#中的协方差和逆变量可能存在问题 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |