省下洗发水钱买书 2022-08-11 21:56 采纳率: 0%
浏览 97
已结题

.NET 6.0下关于Json解析的dll的相关问题

问题遇到的现象和发生背景

System.Web.Extensions.dll和Newtonsoft.Json.dll在.NET 6.0下是不能用了吗?为什么找不到支持.NET6.0版本的dll,而且每次使用低版本就报下面这个错误:

img

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. 系统找不到指定的文件。
File name: 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   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 System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContract(Object value)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe(Object value)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value)
   at Game.MainClass.Main(String[] args) in E:\My Project Directory\Visual Studio Project\Test\Test\Program.cs:line 15
问题相关代码,请勿粘贴截图
using System;
using Newtonsoft.Json;

namespace Game
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Player player = new Player();
            player.id = 1;
            player.name = "player";
            player.coin = 100;

            string m1 = JsonConvert.SerializeObject(player);
            Player m2 = JsonConvert.DeserializeObject<Player>(m1);

            Console.WriteLine(m1);
            Console.WriteLine(m2.ToString());
        }
    }
}
  • 写回答

1条回答 默认 最新

  • LiuDuanWu 2022-08-11 22:34
    关注

    这个很low的各个版本都不兼容 直接报错
    建议使用JavaScriptSerializer类来转换

    评论

报告相同问题?

问题事件

  • 系统已结题 8月19日
  • 创建了问题 8月11日