I have a DLL project that uses the SendGrid Nuget package. The SendGrid package requires the Nuget package System.Net.Http 4.3.4. This DLL project I've then packaged into a Nuget package.
Now, I have a ASP.NET MVC project that includes my Nuget package. Because of dependency requirements installing it installs SendGrid, System.Net.Http, and other dependencies.
Now, when I have my web app try to send an email I got the following error.
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
…
Now, I'm confused since I thought version 4.3.4 was installed. I checked the version of System.Net.Http in all my projects and it says it's version 4.2.0.0. Ok, I'm confused why it's showing 4.2 when I thought I installed 4.3.4. However, if 4.2 is referenced in my project how could it not find it?
Anyway, next I looked at my web.config file and saw this
<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>
I don't know anything about these binding redirect. But I decided to remove this and everything worked fine.
So my question is why?
Thanks
About binding redirects
Binding redirects allow the runtime to select alternative versions of a specific assembly. Binding redirects can be helpful because they reduce the strictness for binding to a specific version of an assembly. But, they can bring about conflicts.
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions
Binding redirect after adding SendGrid
I noticed that adding a NUGET reference to SendGrid inserted the following binding redirects
<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>
Creating a NUGET package that uses SendGrid
I created a simple class library project which references SendGrid and made a NUGET package. I placed this NUGET package in my private feeds folder and then referenced this NUGET package from another Framework project. The compiled .CONFIG file had the following binding redirect
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<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>
Possibility
My thoughts:
Hope this helps.
User contributions licensed under CC BY-SA 3.0