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
Newtonsoft.Json dependency issues #422
Comments
Having same issue here using Newtonsoft Json v10.0.3. Was already in a project that I added Twilio to. |
Hi. I am having this issue as well. Newtonsoft v9.0.1 is installed together with Twilio, and this error occurred. I tried downgrading Newtonsoft and Twilio to different versions but still having the error. Anyone knows how to fix this? |
I am in the same boat, Doesn't matter what is in the bindingRedirect from Nuget in the app.config it still displays this error. It is like Twilio is somehow finding an old version of newtonsoft.json to load. |
Can you provide more details of your app and environment? |
In my case I am using Twilio for 2FA to send SMS tokens. I have recently updated my Nuget packages which now has Newtonsoft.Json v11 installed, there is a bindingRedirect in my app.config and in deployment the the app.config is correctly call .exe.config and is being used as I have other settings in there that my app is seeing. <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Cors" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.6.0" newVersion="5.2.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Tokens" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime> Other packages that depend on Newtonsoft.Json such as Owin, SignalR are working OK, so not sure why Twilio is specifically looking for 9. I have checked in my references and ensured all references have Specific Version = False, and in the application path only 1 DLL for Newtonsoft.Json is there which is 11. Error occurred on server: FileLoadException |
This is the same as #431 |
Same as #405 |
Does someone have a .csproj they could share with us that reproduces the issue? |
What version of VS and .net? I've never had an issue using the latest version of Newtonsoft.Json in my projects, I've upgraded a few of them more than once... this is the whole point of binding redirects, if you have multiple versions present, you specify which your application uses. Perhaps you're running into an issue with automatic binding? Note that automatic redirection does not modify the source app.config so essentially you wouldn't see it. https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection |
I can reproduce the error if I manually edit my .csproj reference to version 9... with 11 installed..
when it should be
|
it is strange, in my case all on my proj files have <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference> This is my Twilio reference <Reference Include="Twilio, Version=5.14.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Twilio.5.14.1\lib\net451\Twilio.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference> |
OK so I have created a new project added in SignalR to have a reference to Newtonsoft 11 already in my project, then added Twilio and setup a quick test, shockingly it works fine... :( so agreed @dsghi there is something happening somewhere. I know in my case I also removed the Twilio.Signed package and replaced it with Twilio (as I am not doing Strongly Typed Signed assemblies anymore. So I will keep going through my project references and try and work out what is happening. The plot thickens |
Good luck! |
So is there an answer here? I have several C# console apps and a website (VS2017, .NET 4.7.1, C#). When I let Nuget update my package references, this happens as the original poster indicates. In the past, I've had to go back to the old version of Newtonsoft, but this strikes me as a problem with the Twilio DLL, and there ought to be a better solution then having a bunch of assemblybindings littering everything up, or being held to old dependency. "Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. " |
We cannot reproduce the issue @mnoreen. Would you be able to share a full project with us that exhibits the behavior? |
I can recreate one (I've just gone through and reverted everything to "old" versions). However, I would say, you don't even need a "project" file. I have a .NET webforms-based website (targets the 4.7.1 framework and we use VS 2017 to manage it). There is no project file there. There is a web.config. The nuget package manager pulls in the latest DLLs, then updates the web config with the assembly bindings that aussiealf mentions earlier in this thread. I have a page that allows us to send an SMS message out using Twilio. When I let the nuget package manager update everything, it throws the exception that is the subject of this thread. When I revert back to the old Newtonsoft (and other dependent dlls), and yank out the assembly bindings, it works. Pretty cut and dry. Same thing happened the last time I tried to update to the latest Twilio dll. I'm just getting concerned about having some very old DLL dependencies. @dprothero |
Here is the console app I created today the exhibits the problematic behavior. When I build it, I get the following in the Output window:
I haven't been able to track all the details down yet, but there's something about the "Auto-generate binding redirects" checkbox (go to project properties, then the Application tab). Checking that box, the build warnings go away. I have no app.config, so I'm not sure what that did. Does rebuilding somehow change what gets compiled into the .exe.? I'm beginning to wonder if there's some issue with nuget, app.configs, and some other hidden VS settings... Once I get things working and released into production, I'll try to do some more testing... |
@mnoreen Probably in the |
@mnoreen Your project definitely reproduces the issue. It's possible there's some kind of conflict between the version of Newtonsoft.Json package that Twilio requires and one of the Microsoft Identity libraries requirement. We will continue to research. In the meantime, the workaround is to definitely to enable Automatic Binding Redirection in your csproj files: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection#enabling-automatic-binding-redirects-manually |
Here's a quick way to fix your existing projects that have this issue: In Visual Studio, open the Package Manager Console (Tools... NuGet Package Manager... Package Manager Console) and run the following command: |
Im glad you got a repro project, I tried but couldn't repro on a fresh project. Out of interest David, could it have something to do with the comment I made about the Twilio proj file Currently the Twilio package versioning has [9.0.1) which I believe means it will only use Newtonsoft 9 and all minors, but no newer majors. As per https://docs.microsoft.com/en-us/nuget/reference/package-versioning The only reason why I dont think this is it is the fact that this is purely a Nuget config issue, so we shouldn't be getting a FileLoad error in our .NET app cause this wouldn't look at the Nuget environment anyway. The thing that gets me is that I have the binding redirect there but it doesn't seem to adhere to that binding. |
@aussiealf I believe I believe the root of the problem is when you have multiple packages that have different versions of JSON.NET required and the only way to solve that is with binding redirects. We don't normally run into these because automatic binding redirects is typically turned on by default. |
I was wondering if there was anymore discussion / resolution to this. For some reason, I decided to give Twilio another shot. I have a C# .NET class library with Newtonsoft.Json already added to it (12.02, latest rev as of now). I used nuget to add Twilio (5.30.0). My class library DLL wraps up a bunch of boilerplate code so my console app basically just has to call a simple .Send() method. I still get an exception thrown when the class library calls MessageResource.Create(): "Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0" Oddly enough, the SMS text message is sent to my cell phone, I just also get the exception in my code: Exception particulars include: InnerException: null
|
@mnoreen are you using the Nuget library, or do you have the source in your solution? |
@rheldt I used nuget to add the "Twilio REST API helper library" (v 5.30.0) |
@mnoreen I ended up resolving this by dropping the Twilio source in my solution rather than using the Nuget library. That lets me use the same version of Json.Net across the solution. No, it's not ideal, but it works nicely. Alternatively, you could downgrade to Json.Net version 10 in your solution and use the Nuget library. See if that works? |
@rheldt Yes, I did downgrade Json.Net to v10 and it did work. I just think this seems to be a long standing "issue"...? When you say "dropping the Twilio source in my solution..." could you elaborate? I'm not sure I quite follow, but I like where you going with it! I would like to have the same version of Json.Net across my solution (as I have a large number of console apps that rely on my core/common class lib). |
@mnoreen You'd need to download the source: Include that project in your solution. Then, add references to your other project(s) that needs Twilio. You will probably also need to add a few Nuget libraries. I'm using the following, but YMMV: |
|
Try renaming the Newtonsoft.Json.dll from below locations and rebuild your project. Visual studio actually looks for Newtonsoft.Json.dll from below locations by default. C:\Program Files\Microsoft SDKs\Azure.NET SDK\v2.9\bin\plugins\Diagnostics C:\Program Files\Microsoft SDKs\Azure.NET SDK\v2.9\ToolsRef C:\Program Files (x86)\MSBuild\Microsoft\NuGet C:\Program Files (x86)\Common Files\microsoft shared\VsHub\1.0.0.0\lib C:\Program Files\IIS\Microsoft Web Deploy V3 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend |
Hello @clydewallace, @mnoreen, I'm checking in to find out if folks are still having an issue with the latest version of this helper library. I was not able to reproduce the issue utilizing the following steps:
With best regards, Elmer |
@thinkingserious I just went through the process of giving this another go around... I have two large Visual Studio solutions, one that contains a bunch of console apps and one asp.net website (webforms), all targeting .NET Framework 4.8. In both, I used nuget to update package references: Twilio Newtonsoft.Json Unfortunately for me... the problem persists... specifically with the asp.net website. As soon as I call the MessageResource.Create() method, it throws an 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. … " Again, the "odd thing" (although ALL of this is odd to me!) is that it SMS message does get sent (I got the text message on my iPhone); the MessageResource.Create() method "worked" but also threw that exception, so as far as my code knows, it didn't work... I used nuget to go back to Newtonsoft.Json 10.0.3 and it works with no exceptions again. |
Hello @mnoreen, I was unable to reproduce the error in a Windows Forms App (.NET Framework) app. Here are the steps I followed:
private void ButtonSendSMS_Click(object sender, EventArgs e)
{
var twilioAccountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
var twilioAuthToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
TwilioClient.Init(twilioAccountSid, twilioAuthToken);
MessageResource.Create(
new PhoneNumber(Environment.GetEnvironmentVariable("MY_PHONE_NUMBER")),
from: new PhoneNumber(Environment.GetEnvironmentVariable("TWILIO_PHONE_NUMBER")),
body: "Hello World!"
);
}
Could you please let me know if I'm missing anything with respect to duplicating your development environment? With best regards, Elmer |
@thinkingserious It seems to work ok in my console apps, even without binding redirects. But not the asp.net website w/out dropping back to the older version of Newtonsoft.Json. |
Hi @mnoreen, I have attempted to re-create the issue with the proper project type. For this test, I used the ASP.NET Web Application (.NET Framework) template and selected Web Forms as the project type with a target of .NET Framework 4.8. (Is that the correct project template?) Newtonsoft.json version 12.0.2 was pre-installed, so I bumped it to 12.0.3 and then installed Twilio 5.38.0 via Nuget. I then added the following code to void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
var twilioAccountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
var twilioAuthToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
TwilioClient.Init(twilioAccountSid, twilioAuthToken);
MessageResource.Create(
new PhoneNumber(Environment.GetEnvironmentVariable("TWILIO_PHONE_NUMBER")),
from: new PhoneNumber(Environment.GetEnvironmentVariable("TWILIO_PHONE_NUMBER")),
body: "Hello World!"
);
} When I run the app (it launched in the web browser), I receive the SMS without error. Perhaps I'm not looking in the right place for the error or my settings are less stringent than yours. In what window are you seeing the exception? Also, in the Exception Settings tab, you may have checked off more items in the With best regards, Elmer |
Unfortunately, no that's not quite the same environment. That's a web APPLICATION project, not a website. I was able to completely reproduce this by starting "from scratch."
Ran the website, clicked the button, and bam. Exception as per usual. I ran it through the debugger and as soon as it stepped over the Create() method, I got the text message on my iPhone and the exception was thrown. I don't know how to make it any more straightforward than that. `
` |
@thinkingserious
In the App_Code directory, I created class to hold the "constants" for the Account SID and Token values as well as my "to" and "from" phone numbers. Before I zipped up this code, I replaced those with junk values, but that should be pretty obvious. |
Hello @mnoreen, Thanks for the additional detail! It turns out that the template for creating an empty ASP.NET Web Site was removed in Visual Studio 2019 and can be installed via these instructions. After downloading and installing that template, I executed the following steps:
Could you please review the steps above and please note where I diverged from your setup? Thanks! |
@thinkingserious As you can imagine, things are bit crazy right now. It might take a few days before I can get back to this. But while I have you... does this mean that you think the issue is closed? I'm a bit concerned that this issue isn't being taken seriously enough to debug. I appreciate your attention the last couple of days, really! But this has been raised on and off for... years now?! Just concerned about what the message for developer support is. |
Hello @mnoreen, I have not closed the issue because you are still experiencing the exception. My next goal for this issue is to reproduce the exception locally. I believe it could be a setting in Microsoft Visual Studio 2017, that I'm not seeing on my end, effecting the build. Perhaps the next step is to attempt to reproduce the exception within the Microsoft Visual Studio 2017 environment vs. 2019. Thanks! |
At the Visual Studio download page I see two versions of Visual Studio Community 2017 (15.0 and 15.9). Could you please verify which one you have? Thanks! |
15.9.21 We have the Professional version, not Community. And we tend to keep up with Microsoft's updates. This website of ours was originally created in much older versions of VS. Not sure why it would matter, but I could believe there's something to it. It's files. I get the exception when I run our original website on my localhost in vs2017 or vs2019. It also occurs when running on our development and test web servers (full Windows Server 2016, full IIS, no VS). When I get more time I can try running that small prototype I uploaded earlier in VS2019, and also on our dev and test servers. Thx! |
Ah, given you can reproduce in vs2019, I'll await your prototype for further testing. Thank you! |
@thinkingserious *Result is:
When I let the exception be rethrown (w/out capturing it first), I also noticed an Assembly Load Trace section that may help:
|
@thinkingserious To my eye, it appears that when I run my test page, the Newtonsoft.Json library that is loaded is the the v12 version. That seems "correct" to me since that's what is in my websites Bin folder. But then, when I call the twilio method that in turns calls a Newtoonsoft.Json method, the exception is thrown because for some reason it explicitly wants the v10 version. Hopefully you will be able to discern more and come up with a resolution. Thanks! |
Can you please tell me which other .NET libraries (particularly open source ones) you have used that don't exhibit this issue? I want to do some comparisons on how those projects are defining dependencies to Newtonsoft.json. Thanks! |
@mnoreen I was able to recreate the issue you're seeing in VS2019 using the sample project you provided. But I'll defer to the comment here for why this is happening: #431 (comment) High-level, binding redirects are required to avoid this issue and VS is able to help out. Just by upgrading the Twilio package version using NuGet in your sample project it added the appropriate binding redirects and the issue went away. I don't see anything we can/should do in this repo to alleviate the issue as it's core to .NET |
Could not load file or assembly 'Newtonsoft.Json, Version=9.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)
To reproduce, simply install twilio via nuget after newtonsoft is already installed because you will most certainly have a more updated version of newstonsoft.
Exception/Log
Steps to Reproduce
Feature Request
If this is a feature request, make sure you search Issues for an existing
request before creating a new one!
The text was updated successfully, but these errors were encountered: