Reputation: 1249
I'm working on programming a winform app using the google apis. I just added the youTube v3 api, and now I'm getting the error:
An unhandled exception of type 'System.TypeInitializationException' occurred in Google.Apis.Auth.dll
Additional information: The type initializer for 'Google.Apis.Json.NewtonsoftJsonSerializer' threw an exception.
And the inner exception is:
{"Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"}
I've been trying to fix this for an hour, so any suggestions are appreciated.
I'm using the latest version of all the NuGet packages, no updates are available.
The apis I'm using are: https://www.nuget.org/packages/Google.Apis.Drive.v2/ https://www.nuget.org/packages/Google.Apis.YouTube.v3/
Upvotes: 4
Views: 7157
Reputation: 1428
I had this error. I was using Visual Studio 2017 and I had the current version (at the time) of Newtonsoft.Json installed (11.0.2). When I installed the current version of the Google.Apis (1.35.1), I received the error "The type initializer for 'Google.Apis.Json.NewtonsoftJsonSerializer' threw an exception". When looking at the inner exception information I found that the Google.Apis was expecting Newtonsoft.Json version 10. I removed Newtonsoft and Google.Apis and then reinstalled google.apis via nuget. Version 10 of Newtonsoft.Json was also installed automatically and the error went away.
If anyone is also having this error, make sure the version of Newtonsoft that is expected by Google.Apis is actually installed.
Upvotes: 2
Reputation: 1249
I found the answer, I had accidentally deleted the reference to the Newtonsoft.Json package, and when I added it back in I somehow selected an older version from a different project's packages instead of my projects packages.
Once I added the correct dll from my current project packages, it all worked fine.
Upvotes: 4