C# 从条带获取响应时出错;无法加载文件或程序集';System.Collections.Immutable';
引用的条带库:Stripe.netC# 从条带获取响应时出错;无法加载文件或程序集';System.Collections.Immutable';,c#,.net,asp.net-mvc,stripe-payments,C#,.net,Asp.net Mvc,Stripe Payments,引用的条带库:Stripe.net 运行时版本:v4.0.30319 版本:25.2.0.0 从条带中获取响应并在中调用charge函数()时,我收到错误“无法加载文件或程序集'System.Collections.Immutable,Version=1.2.3.0,Culture=neutral” 下面提到的代码 <form action="/Pay/Charge" method="POST"> <article> <label>Am
运行时版本:v4.0.30319
版本:25.2.0.0 从条带中获取响应并在中调用charge函数()时,我收到错误“无法加载文件或程序集'System.Collections.Immutable,Version=1.2.3.0,Culture=neutral” 下面提到的代码
<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>
如果已经安装System.Collections.Immutable,请在packages.config中检查它的版本,如果它是另一个版本,则无法工作,请手动将其修改为与异常中记录的版本相同的版本,然后重新生成解决方案以安装所需的版本
<package id="System.Collections.Immutable" version="1.2.3.0" targetFramework="net45" />
更新:
最初的问题是关于Stripe.net的25.2.0版本,在旧版本中依赖于System.Collections.Immutable
,但是的最新版本不再依赖于:
查看链接
希望这有用。以下是我在尝试解决此问题时的看法:
System.Collections.Immutable
添加到我的web.config
文件中(或者,如果您碰巧在桌面应用程序上工作,则是应用程序配置)。在此错误之前,web.config中没有该程序集的条目NuGet
程序包版本与程序集版本不同。这阻碍了我几个小时,因为我知道我必须将版本重定向添加到我的web.config
NuGet
软件包版本是1.7,而程序集版本是1.2.5.0
。最后,我通过PowerShell发现了这一点:
PS> [Reflection.AssemblyName]::GetAssemblyName('C:\Users\MyUserName\Documents\WebAppSourceCodePath\bin\System.Collections.Immutable.dll').Version
Major Minor Build Revision
----- ----- ----- --------
1 2 5 0
知道我添加了此条目:
<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>
由于它是一个nuget包,您确定它已发送到服务器吗?错误消息的重要部分是
找到的程序集的清单定义与程序集引用不匹配。
。这意味着您使用了一个与库所期望的不同的'System.Collections.Immutable
dll。如果你搜索错误信息,你会发现很多重复的信息。解决方案是在web.config中添加一个绑定重定向,该重定向指向已添加到项目中的dll版本。如果您通过NuGet添加该程序集,绑定重定向元素将自动添加这是一个演示项目,我正在我的本地机器@BugFinder上尝试最新的稳定版本is 1.5。添加该版本,并确保web.config包含一个重定向到此的条目。我在Stripe.NET 26.1.0中面临同样的问题。而现在最新版本的System.Collections.Immutable
是1.7.0。我假设它与1.2.3.0向后兼容,我不明白Stripe.NET为什么会在这个可传递依赖项上出错……为什么1.5或1.7不能与1.2.3.0向后兼容?我真的不想仅仅因为Stripe内部有问题就降低该软件包的级别。NET@CsabaToth最新版本对System.Collections没有依赖性。不可变的
,我会更新我的答案,请检查
PS> [Reflection.AssemblyName]::GetAssemblyName('C:\Users\MyUserName\Documents\WebAppSourceCodePath\bin\System.Collections.Immutable.dll').Version
Major Minor Build Revision
----- ----- ----- --------
1 2 5 0
<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>
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