System.Security.Permissions missing when invoking JsonConvert.DeserializeObjectlt;Tgt; in .NET Core 2.0(调用 JsonConvert.DeserializeObjectlt;Tgt; 时缺少 System.Security.Permissions在 .NET Core 2.0 中)
问题描述
我目前正在考虑使用 .NET Core 2.0,以便可以在多个平台上运行我的应用程序.
I am currently looking at using .NET Core 2.0 so that I can run my app on multiple platforms.
我需要做的一件事是获取一个传入的字符串并将其反序列化为一个对象.例如
One thing I need to do is take an incoming string and deseralise it into an object. e.g.
var resultingObject = JsonConvert.DeserializeObject<MyDataContract>(request);
在完整的 .NET 中,这将运行并返回我的对象.但是在 .NET Core 2.0 中出现以下异常
In full .NET, this would run and return me my object. However in .NET Core 2.0 I get the following exception
Could not load file or assembly 'System.Security.Permissions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
at Newtonsoft.Json.Serialization.JsonTypeReflector.get_DynamicCodeGeneration()
at Newtonsoft.Json.Serialization.JsonTypeReflector.get_ReflectionDelegateFactory()
at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator(Type createdType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
经过一番阅读后,我在 StackOverflow 上发现了这一点,这表明 .NET Core 中不允许这种操作 https://stackoverflow.com/a/38385774/1211743
After some reading around I found this on StackOverflow which suggests that this kind of operation is not permitted in .NET Core https://stackoverflow.com/a/38385774/1211743
有人有什么见解吗?
推荐答案
这是由于对 .NET Core 的工作原理缺乏了解.我打开了 csproj 并添加了对所需文件System.Security.Permissions"的引用并重新加载了项目.至此,nuget 解决了.Json.NET 现在按预期工作.
This was due to a lack of understanding of how .NET Core works. I opened up the csproj and added a reference to the required file 'System.Security.Permissions' and reloaded the project. At this point, nuget resolved it. Json.NET now works as expected.
这篇关于调用 JsonConvert.DeserializeObject<T> 时缺少 System.Security.Permissions在 .NET Core 2.0 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:调用 JsonConvert.DeserializeObject<T> 时缺少 System.Security.Permissions在 .NET Core 2.0 中
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
