-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google.Apis version doesn't work with newer version of Newtonsoft.Json #1464
Comments
I've used Google Cloud APIs with recent versions of Newtonsoft.Json with no problems. Could you clarify exactly what errors you're seeing, and where you're seeing them? My guess is that this is a matter of assembly binding redirects getting messed up. |
Question was cross posted on stack overflow |
Here is my detailed scenario: I updated Newtonsoft.Json to 12.0.2 via NuGet Package Manager. At this section var certificate = new X509Certificate2(...); 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" Then I updated the followings via NuGet Package Manager: Google.Apis from 1.36.1 to 1.41.1 And I still got the exception. I does not want to use Google Cloud Platform because is not free. |
Right - that sounds like the problem is missing assembly binding redirects. I suggest you check your config file for what assembly binding redirects are present, and see whether there's one for Newtonsoft.Json at all. You may find that removing the Newtonsoft.Json dependency and then adding it again fixes the redirect. Or you could try deleting all the assembly binding redirects, and let VS recreate them for you. See this documentation for more details. |
I uninstalled all Google.Apis packages and Newtonsoft too. I deleted all references for these packages. I reinstalled Newtonsoft first, then the rest of the Google.Apis packages, I checked my web.config to don't have any reference for these packages and the exception still appears. |
Yes, Google.Apis.Core is built against 10.0. But that's where the assembly binding redirects come in - there should be one to tell the runtime "when something looks for 10.0, use 12.0.2 instead". I've just tried this in a fresh ASP.NET MVC application, just "File / New Project", then adding Google.Apis.Core, then updating Newtonsoft.Json, and the assembly binding redirect appeared correctly. This is in web.config, within the <dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly> If you haven't got an element like that, you should just be able to add it in manually. It's a bit concerning that it wasn't generated automatically though - you may well have the same problem (with any package) in the future. |
Unfortunately your suggestion not solved my problem. It's not working with these assembly binding redirects.
Thank you for your help! |
While I'm glad that's working for you, I don't think that's a sustainable approach. You'll have a lot of work to do any time you want to update the library, and you'll run into exactly the same problem if you later want to add any other dependencies that use a different version of Newtsoft.Json. The assembly binding redirect should work, and I'd strongly encourage you to look further into why it's not working for you. I suspect this would be something specific to your project - without a way of reproducing the problem, there's nothing more we can do to help you. I'm going to close this issue now, as I don't believe there's anything to do in this repo. If you want me to help you get to the bottom of the problem, I would suggest you try to reproduce the issue in a minimal way, and edit your Stack Overflow question so that anyone can reproduce it. We can then try to get the redirects working for you. |
I have the same problem. |
@jskeet has there been any talk about moving this library from Newtsoft.Json to System.Text.Json? |
@LindaLawton: We expose Newtonsoft.Json-specific types - changing it now would be a breaking change, requiring a major version bump. Maybe if we ever do create a new major version, it would be worth moving - but I'm not expecting that any time soon. (Note that System.Text.Json isn't available for .NET Framework prior to 4.6.1, and currently these libraries support 4.5 as well...) |
@jskeet as .NET Framework 4.5.2, 4.6, 4.6.1 will reach End of Support on April 26, 2022 does it matter if we still support 4.5? Just a note for when you do decide to dump the version. |
@LindaLawton: Well, we'd have to see at that point - I'm just saying it's another reason why we couldn't do it right now. We're not actually planning a major version bump anyway though, so please don't hold your breath :) |
Sorry, but may be you have any ideas about my trouble?
|
@EgoPingvina: Sorry, I thought I'd replied to you before; I must have been half way through and got distracted. Please file a new issue with more details. We can't really tell much just from what you've said. I assume there's a newer version being used somewhere and the library resolver isn't working properly for whatever reason - but until we can reproduce the issue or at least know more about the project structure, target framework version etc, it's going to be hard to help. |
I tried to downgrade Newtonsoft.Json to 12.0.3 and 12.0.1 - it didn't help. Also tried to downgrade FirebaseAdmin - didn't help too. For deploy I use |
@EgoPingvina: Again, please file a new issue. If at all possible, it would be great for that new issue to contain a complete example so that we can reproduce the problem ourselves. |
I am using Google.Apis version 1.36.1 in a web application in .NET Framework 4.7.2 whizh 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.
Any idea how can I solve this problem? Maybe Google.Apis should be do an upgrade?
Thanks in advance!
UPDATE:
I figured out what was the problem. I updated Newtonsoft from version 10.0.2 to 12.0.2. The assembly binding redirect appears into my web.config file, which is expected:
The problem why doesn't work the binding redirect was that namespace in my tag into my web.config:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
I deleted the namespace xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" from tag and the assembly binding redirect is working now.
This post was helped me: https://stackoverflow.com/questions/1751775/binding-redirect-problem-in-net/12011221#12011221
Thanks for all of you to try to helping me
The text was updated successfully, but these errors were encountered: