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