Could not load file or assembly Newtonsoft.Json
Hi I try to Send photo and file with SendPhotoAsync and SendDocumentAsync. When i use from my main project the error will occur which i will explain, but when i create a test website solution and test in that it work well. if you need i will explain more about the project architecture.
But, about the Error, that`s it:
Could not load file or assembly 'Newtonsoft.Json, Version=6.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)
and Full base messsge:
System.IO.FileLoadException:``Could not load file or assembly 'Newtonsoft.Json, Version=6.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) File name: 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter..ctor() at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() at System.Net.Http.Formatting.MediaTypeFormatterCollection..ctor() at System.Net.Http.HttpContentExtensions.get_DefaultMediaTypeFormatterCollection() at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, CancellationToken cancellationToken) at Telegram.Bot.TelegramBotClient.<SendWebRequestAsync>d__139``1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter``1.GetResult() at Rubik_Telegram.Sending.Send.<SendPhotoByFileAsync>d__f.MoveNext() in ...\Send.cs:line 161 === Pre-bind state information === LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed (Fully-specified) LOG: Appbase = file:///.../myprojectfolder/ LOG: Initial PrivatePath = ...\myprojectfolder\bin Calling assembly : System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. LOG: This bind starts in default load context. LOG: Using application configuration file: ...\web.config LOG: Using host configuration file: C:\Users\...\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed LOG: Attempting download of new URL file:///C:/Users/.../AppData/Local/Temp/7/Temporary ASP.NET Files/vs/f7e4c2e3/711202e2/Newtonsoft.Json.DLL. LOG: Attempting download of new URL file:///C:/Users/.../AppData/Local/Temp/7/Temporary ASP.NET Files/vs/f7e4c2e3/711202e2/Newtonsoft.Json/Newtonsoft.Json.DLL. LOG: Attempting download of new URL file:.../bin/Newtonsoft.Json.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Something is strange, both SendPhotoAsync and SendDocumentAsync, throw this exception but, the document send well, but the photo don`t send anyway.
Also i had this problem before in another project but with some solutions i solved that, and i did all of those solutions and all others said in Stack and other results in google, but those don`t work this time.
Thanks from any help.
Environment data
IDE and PRJ:
- Visual Studio 2013 Ultimate Update 5.
- .NET Framwork Version 4.5.51650
- It`s a Class library project
Packages:
Json.NET
- Created by: James Newton-King
- Version 9.0.1
Microsoft ASP.NET Web API 2.2 Client Library
- Created by: Microsoft.AspNet.WebApi.Client
- Version: 5.2.3
Telegram Bot API
- Created by: Robin Muller
- Version: 10.3.1
Summery Environment data
NuGet Package Version: 10.3.1 .NET Version: 4.5 IDE: VS2013 Ultimate Update 5 App: ASP.NET Website
Hi D4NTESPARDA, Try to add assembly binding redirect in your app.config to last version of Newtonsoft.Json:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
hi and thanks Bolisov, i did this before, but didn`t work.
Hi, try these steps:
- right click on your project.
- click on "Manage Nuget packages"
- in the Update Tab, update all the package.
- rebuild your project. Done
Does this solved the problem?
Yes.. update with latest
@D4NTESPARDA Feel free to reopen this if the issue isn't resolved.
Just for posterity, I want to mention that @matiuspico helped me out here.
I only had to upgrade Newtonsoft.Json (didn't upgrade anything else as I didn't want to break something.)
This was actually for ReactJS.NET, but I'm still glad I found this.
I have similar issue "System.InvalidOperationException: 'Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.'" i have tried the above mentioned solution but the issue is resolved for me
Without changing the version i was able to uninstall and reinstall the same version this worked for me.