c# - ServiceStack Json反序列化错误

标签 c# json .net-core servicestack

这是我的 .net core 2.0 控制台应用程序的代码:

using ServiceStack;
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
     class Program
     {
         static void Main(string[] args)
         {
             var response = $"http://capfeed.com/json"
                 .GetJsonFromUrl(httpReq => httpReq.UserAgent = "Hoho")
                 .FromJson<CapFeedResponse>();

             Console.ReadKey();
         }
     }

     public class CapFeedResponse
     {
         public string success { get; set; }

         public string message { get; set; }

         public List<CapFeedResponseItem> result { get; set; }
     }

     public class CapFeedResponseItem
     {
          public int position { get; set; }

          public string symbol { get; set; }

          public string name { get; set; }

          public long time { get; set; }

          public decimal usdPrice { get; set; }

          public decimal btcPrice { get; set; }

          public long usdVolume { get; set; }

          public long mktcap { get; set; }

          public long supply { get; set; }

          public float change24 { get; set; }
     }
 }

当我运行应用程序时,出现以下异常:

System.TypeInitializationException: 'The type initializer for 'ServiceStack.Text.JsonSerializer' threw an exception.'

FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

我该如何解决这个问题?

最佳答案

当您应该引用 ServiceStack.Text.Core 时,您可能使用了错误的 ServiceStack.Text NuGet 包。

关于c# - ServiceStack Json反序列化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46277734/

相关文章:

c# - WCF Unhandled FaultException 未由用户代码处理

java - 如何使用java复制curl命令?

json - ASP.NET Core 3 - Serilog 如何在 appsettings.json 文件中配置 Serilog.Sinks.Map?

c# - .NET Core WebAPI 依赖注入(inject)解析 null

c# - Entity Framework 正确使用连接表?

c# - 使用 Directory.EnumerateFiles 的可观察异常处理

c# - 使用 C# 使用网络摄像头按命令拍照

json - 多行文件到单个 JSON 字符串

c# - 使用 EF Core 查询中的方法

visual-studio - 带有 Visual Studio 的 Docker 工具箱 - 未启用卷共享