【问题标题】:ServiceStack Json deserialization errorServiceStack Json 反序列化错误
【发布时间】:2018-02-26 21:34:11
【问题描述】:

这是我的 .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: '类型初始化器 'ServiceStack.Text.JsonSerializer' 抛出异常。'

FileNotFoundException:无法加载文件或程序集 'System.Configuration.ConfigurationManager,版本=0.0.0.0, 文化=中性,PublicKeyToken=cc7b13ffcd2ddd51'。系统无法 找到指定的文件。

我该如何解决这个问题?

【问题讨论】:

  • dotnet restore?

标签: c# json .net-core servicestack


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多