3

I am using Google .net client library version 1.36.1 in a web application in .NET Framework 4.7.2 which works with a Newtonsoft.Json version 10.0.2.

I want to include in my web application a class library in .NET Standard 2.0 which uses Newtonsoft.Json version 12.0.2, but I can't, because is an incompatibility issue between these 2 Newtonsoft version.

I wanted to upgrade the Newtonsoft.Json in web app from 10.0.2 into 12.0.2 but it says the Google.Apis doesn't support the newer version of the Newtonsoft.Json.

I have added this as an issue on the client library repo already 1464

Any idea how can I solve this problem? Maybe Google.Apis should be do an upgrade?

Thanks in advance!

UPDATE:

Here is my detailed scenario:

I updated Newtonsoft.Json to 12.0.2 via NuGet Package Manager. At this section

var certificate = new X509Certificate2(...); const string user = "..."; var serviceAccountCredentialInitializer = new ServiceAccountCredential.Initializer(user) { Scopes = new[] { SheetsService.Scope.Drive } }.FromCertificate(certificate); var credential = new ServiceAccountCredential(serviceAccountCredentialInitializer); var service = new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "My Application Name" });

when I initialize the service variable as new SheetsService(...), I got the following exception:

Could not load file or assembly 'Newtonsoft.Json, Version=10.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=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed

Source = "Google.Apis.Core" StackTrace = " at Google.Apis.Json.NewtonsoftJsonSerializer..ctor()\r\n at Google.Apis.Services.BaseClientService.Initializer..ctor()\r\n at OmneaHotLead.WriteInSheetToOmnea(Int32 firNr, IList`1 omnData) in d:\Projects\MyApplication\App_Code\MyCode.cs:line...

Then I updated Google.Apis packages via NuGet Package Manager to 1.41.1. And I still got the exception.

user7745308
  • 176
  • 2
  • 6
  • 2
    Have you tried adding a [binding redirect](https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/bindingredirect-element)? – stuartd Oct 01 '19 at 11:10
  • 1
    Please add more details, either here or in the issue. It's not clear what you mean by "it says the Google.Apis doesn't support the newer version of the Newtonsoft.Json". – Jon Skeet Oct 01 '19 at 12:24
  • I updated my initial post with some details – user7745308 Oct 02 '19 at 06:37
  • do what @stuartd told you. add binding redirect entries – magicandre1981 Oct 02 '19 at 13:44
  • I figured out what was the problem. The assembly binding redirect is not worked for me because I had a namespace in my tag from my web.config. I removed and it's working now. Thanks for all of you to try to helping me – user7745308 Oct 04 '19 at 07:12

0 Answers0