Newtonsoft.Json 程序集冲突 [英] Newtonsoft.Json Assembly Conflict
问题描述
我在我的项目中使用 Netonsoft.Json.它工作正常,直到我开始在我的项目中集成 Paypal SDK.我的代码如下.
I use Netonsoft.Json in my project. It works fine until I start integrating Paypal SDK in my Project. My code is as below.
String AccessToken =
new PayPal.OAuthTokenCredential("", "").GetAccessToken(); ---->>>> This Line Throwing An Error
PayPal.Api.Payments.Address add = new PayPal.Api.Payments.Address();
add.city = TextBoxCity.Text;
add.line1 = TextBoxAddress.Text;
add.phone = TextBoxPhoneNumber.Text;
add.postal_code = TextBoxZipcode.Text;
add.state = TextBoxState.Text;
PayPal.Api.Payments.CreditCard cc = new PayPal.Api.Payments.CreditCard();
cc.number = TextBoxCreditCardNumber.Text;
cc.first_name = TextBoxFirstName.Text;
cc.last_name = TextBoxLastName.Text;
cc.expire_month = Convert.ToInt16(TextBoxExpiryMonth.Text);
cc.expire_year = Convert.ToInt16(TextBoxExpiryYear.Text);
cc.cvv2 = TextBoxCVVNumber.Text;
cc.billing_address = add;
cc.Create(AccessToken);
我得到如下错误
System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.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)
我在互联网上搜索并找到了一些更改配置文件的解决方案.所以我改变我的配置文件如下
I search on internet and found some solution to change config file. SO I change my config file as below
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
我还使用了诸如复制本地"、特定版本"之类的程序集属性,但没有任何方法可以帮助我解决此问题.如何解决程序集冲突?
I also play around with assembly properties like Copy Local, Specific Version but nothing helps me to solve this. How Can I solve assembly conflict?
推荐答案
我刚刚遇到了同样的问题,我通过使用
I just had the same problem and I solved it by updating the Newtonsoft.Json to the latest version using
Update-Package Newtonsoft.Json
然后转到 Web.config 并添加:
and then going to Web.config and adding:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/>
</dependentAssembly>
这篇关于Newtonsoft.Json 程序集冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!