Ubuntu上Newtonsoft.Json.Utilities.ConvertUtils的类型初始化程序抛出异常

时间:2015-03-10 16:02:02

标签: .net linux ubuntu json.net

我们的应用程序在Windows上使用JSON.net就好了。在Linux上(我们在Ubuntu中进行测试)我们得到一个例外:

    An exception was thrown by the type initializer for Newtonsoft.Json.Utilities.ConvertUtils
    20150310_11:51:37.404 ERROR  :    at Newtonsoft.Json.Serialization.DefaultContractResolver.IsJsonPrimitiveType(System.Type t)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(System.Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(System.Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe(System.Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(Newtonsoft.Json.JsonReader reader, System.Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(Newtonsoft.Json.JsonReader reader, System.Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(System.String value, Newtonsoft.Json.JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(System.String value)

InnerException是

Could not load file or assembly 'System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.

在网上的其他地方,他们说可能是我们需要安装" libmono-system-numerics4.0-cil"但apt-get显示已经安装并且已经更新。

我们正在使用.NET 4.0(因为我们希望与Windows XP保持兼容,市场份额仍然很大)。

关于如何让它运行的任何想法?

1 个答案:

答案 0 :(得分:1)

无论出于何种原因,它只是不想与Linux和Linux上安装的版本配合使用。永远不能加载它。

这是我做的最终导致它运行的:

  • 添加了对使用JSON.net的项目的System.Numerics引用
  • 从有效的Windows发行版中抓取System.Numerics.dll(这可能是一个.NET程序集而不是Mono)并将其添加到我的构建过程中,使System.Numerics.dll最终在Linux项目的/ bin / Release目录(与主应用程序的.exe相同的目录)。