error while getting a response from stripe "Could not load file or assembly 'System.Collections.Immutable'

2

Stripe Library referenced : Stripe.net
Runtime Version:v4.0.30319
Version : 25.2.0.0

while getting a response from the stripe and calling the charge function() in am getting the error "Could not load file or assembly 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral" on the code mentioned below

<form action="/Pay/Charge" method="POST">
    <article>
        <label>Amount: $5.00</label>
    </article>
    <script src="//checkout.stripe.com/v2/checkout.js"
            class="stripe-button"
            data-key="@ViewBag.StripePublishKey"
            data-locale="auto"
            data-description="Sample Charge"
            data-amount="500">
    </script>
</form>

This view calls the below charge ActionResult

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

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

//Error on this line--↓

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

            // further application specific code goes here

            return View();
        }


Additional information: Could not load file or assembly 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

InnerException:Null
c#
.net
asp.net-mvc
stripe-payments
asked on Stack Overflow Mar 28, 2019 by Nawaz Khan

2 Answers

0

In case System.Collections.Immutable is already installed, Check out the version of it in packages.config in case it is a different version it won't work, modify it manually to be the same version as it is logged in the exception and rebuild your solution to install the needed version.

<package id="System.Collections.Immutable" version="1.2.3.0" targetFramework="net45" />

Update:

Original question was about version 25.2.0 of Stripe.net and in that old version there was dependency on System.Collections.Immutable, howeever latest version for has no dependency on anymore: enter image description here

Check out the link Stripe.net

Hope this was useful.

answered on Stack Overflow Mar 28, 2019 by Ali Ezzat Odeh • edited Jan 19, 2020 by Ali Ezzat Odeh
0

Here's my take when I tried to fix this problem:

  1. I needed to add System.Collections.Immutable to my web.config file (or if you happen to work on a desktop app it's the app config). Before this error there wasn't an entry for that assembly in the web.config.
  2. The NuGet package version is not the same as the assembly version for whatever reason. This hindered me for several hours, because I knew I had to add a version redirection to my web.config.

Currently the NuGet package version is 1.7, while the assembly version is 1.2.5.0. Finally I found that out with PowerShell:

PS> [Reflection.AssemblyName]::GetAssemblyName('C:\Users\MyUserName\Documents\WebAppSourceCodePath\bin\System.Collections.Immutable.dll').Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      2      5      0

Knowing that I added this entry:

<configuration>
...
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
      <dependentAssembly>
        <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="1.2.5.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
...
</configuration>

Also, you need the proper publicKeyToken and full specification in the entry above. That can be read out using PowerShell as well.

PS> [System.Reflection.Assembly]::LoadFile('C:\Users\MyUserName\Documents\WebAppSourceCodePath\bin\System.Collections.Immutable.dll').FullName
System.Collections.Immutable, Version=1.2.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
answered on Stack Overflow Jan 24, 2020 by Csaba Toth

User contributions licensed under CC BY-SA 3.0