Sean Colombo
Sean Colombo

Reputation: 1529

An exception was thrown by the type initializer for Newtonsoft.Json.Utilities.ConvertUtils on Ubuntu

Our app uses JSON.net just fine on Windows. On Linux (we're testing in Ubuntu) we get an exception:

    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)

The InnerException was

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

On other spots online, they said it could be that we needed to install "libmono-system-numerics4.0-cil" but apt-get shows that to be installed already and up-to-date.

We're using .NET 4.0 (because we want to stay compatible with Windows XP, the market share is still significant).

Any ideas on how to get it running?

Upvotes: 0

Views: 3572

Answers (1)

Sean Colombo
Sean Colombo

Reputation: 1529

For whatever reason, it just doesn't want to cooperate with the version installed on Linux & can never load it.

Here's what I did that eventually led it to run:

  • Added System.Numerics reference to the project that uses JSON.net
  • Grabbed the System.Numerics.dll from the Windows distribution that worked (this is probably a .NET assembly instead of Mono) and added that to my build process in such a way that the System.Numerics.dll ends up in the /bin/Release directory of the Linux project (the same directory as the .exe for the main app).

Upvotes: 2

Related Questions