【发布时间】:2018-02-13 12:28:20
【问题描述】:
我目前正在考虑使用 .NET Core 2.0,以便可以在多个平台上运行我的应用程序。
我需要做的一件事是获取一个传入的字符串并将其反序列化为一个对象。例如
var resultingObject = JsonConvert.DeserializeObject<MyDataContract>(request);
在完整的 .NET 中,这将运行并返回我的对象。但是在 .NET Core 2.0 中出现以下异常
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 中不允许这种操作@
有人有什么见解吗?
【问题讨论】:
-
为了让我们能够提供适当的帮助,我们需要一个 MVCE 与...