我有一个使用SendGrid Nuget包的DLL项目。 SendGrid软件包需要Nuget软件包System.Net.Http 4.3.4。然后将这个DLL项目打包到一个Nuget包中。
现在,我有一个包含我的Nuget包的ASP.NET MVC项目。由于安装依赖项的要求,因此会安装SendGrid,System.Net.Http和其他依赖项。
现在,当我使用Web应用程序尝试发送电子邮件时,出现以下错误。
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Source=Bc3.Mail
StackTrace:
at Bc3.Mail.MailHelper.SendMessage(SendGridMessage message) in C:\Code\Shared Libraries\Bc3.Mail\Bc3.Mail\MailHelper.cs:line 166
at Bc3.Mail.MailHelper.SendMail(MailMessage mail) in C:\Code\Shared Libraries\Bc3.Mail\Bc3.Mail\MailHelper.cs:line 128
…
现在,由于我认为已安装4.3.4版本,我感到困惑。我检查了所有项目中的System.Net.Http版本,并说它是4.2.0.0版本。好的,我感到困惑,为什么当我以为安装4.3.4时却显示4.2。但是,如果我的项目中引用了4.2,怎么找不到呢?
无论如何,接下来我查看了我的web.config文件并看到了这个
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
</dependentAssembly>
我对这些绑定重定向一无所知。但是我决定删除它,一切正常。
所以我的问题是为什么?
谢谢
关于绑定重定向
绑定重定向允许运行时选择特定程序集的替代版本。绑定重定向很有用,因为它们降低了绑定到特定版本程序集的严格性。但是,它们会引起冲突。
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions
添加SendGrid后绑定重定向
我注意到向SendGrid添加NUGET引用插入了以下绑定重定向
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
</dependentAssembly>
可能性
我不确定。我认为,您在web.config中看到的绑定重定向可能是由于对其他NUGET软件包
的无意引用而导致的。