1

Here I am trying to implement stripe for payment gateway in .net mvc My View code is as below.

@{
    ViewBag.Title = "Index";
}
<link type="text/css" rel="stylesheet" href="https://checkout.stripe.com/v3/checkout/button-qpwW2WfkB0oGWVWIASjIOQ.css">
<script src="/Scripts/jquery-1.7.1.js"></script>
<form action="/Home/Charge" method="POST">
<article>
<label>Amount: $5.00</label>
</article>
<script src="//checkout.stripe.com/v2/checkout.js"
class="stripe-button"
data-key="My Public key"
data-locale="auto"
data-description="Sample Charge"
data-amount="500">
</script>
</form>

The code in controller is as below.

 public ActionResult Charge(string stripeEmail, string stripeToken)
        {
            var customers = new StripeCustomerService();
            var charges = new StripeChargeService();

            var customer = customers.Create(new StripeCustomerCreateOptions
            {
                Email = stripeEmail,
                SourceToken = stripeToken
            });

            var charge = charges.Create(new StripeChargeCreateOptions
            {
                Amount = 500,//charge in cents
                Description = "Sample Charge",
                Currency = "usd",
                CustomerId = customer.Id
            });

            return View();
        }

And the secrete key which I have kept in Global.asax.cs file like

StripeConfiguration.SetApiKey("My Sescrete key");

After completing all this part i am runnng my application. when am reaching to

var customer = customers.Create(new StripeCustomerCreateOptions
            {
                Email = stripeEmail,
                SourceToken = stripeToken
            });

this part, then here i am getting the error as

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)

enter image description here

And when I am Installing Newtonsoft.Json with 9.0.1 version then again it start giving the same issue but for the Version=4.5.0.0 which arises at very biging in the gloabal.asax.cs file at below line.

WebApiConfig.Register(GlobalConfiguration.Configuration);
Madhav
  • 559
  • 2
  • 11
  • 34
  • Possible duplicate of [Could not load file or assembly or one of its dependencies](https://stackoverflow.com/questions/4469929/could-not-load-file-or-assembly-or-one-of-its-dependencies) – mmushtaq Jan 19 '18 at 05:25

3 Answers3

1

Late response, but might help someone. If it so happens that your application has a higher version of Netwonsoft deployed, say v.11.0.2 and your application complains about v.9.0 make sure that you have binding redirect configured in the app.config like :

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <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>
    </assemblyBinding>

. And when you deploy your application to production, make sure the config file seats next to your dll or exe.

Farai
  • 180
  • 2
  • 12
0

If you have several projects in your solution please update Newtonsoft.Json in all projects. multiple projects in your solution may have Newtonsoft.Json, but some were at different versions.

Krishan
  • 2,356
  • 6
  • 36
  • 47
-1

Resolved the issue by removing the line of code

WebApiConfig.Register(GlobalConfiguration.Configuration);

from Global.asax.cs file

Madhav
  • 559
  • 2
  • 11
  • 34