sendgrid-csharp: Exception when creating SendGridAPIClient
Issue Summary
I get the following exception when attempting to use SendGrid:
An unhandled exception occurred while processing the request.
FileLoadException: Could not load file or assembly ‘System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) System.Net.Http.WinHttpHandler…cctor()
TypeInitializationException: The type initializer for ‘System.Net.Http.WinHttpHandler’ threw an exception. System.Net.Http.WinHttpHandler…ctor()
Steps to Reproduce
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); var client = new SendGridClient(apiKey); var from = new EmailAddress("test@example.com", "Example User"); var subject = "Sending with SendGrid is Fun"; var to = new EmailAddress("test@example.com", "Example User"); var plainTextContent = "and easy to do anywhere, even with C#"; var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>"; var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); var response = await client.SendEmailAsync(msg);
Technical details:
This is from a .net core web application targeting the full framework as follows: <TargetFramework>net461</TargetFramework>
Below are the full package references:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" />
<PackageReference Include="AutoMapper" Version="6.0.2" />
<PackageReference Include="Sendgrid" Version="9.4.1" />
<PackageReference Include="WindowsAzure.Storage" Version="8.1.1" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="1.1.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Device" />
<Reference Include="System.Drawing" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 22 (11 by maintainers)
@dannythomas13,
That is the correct approach; however, it looks like we have to fix some dependency issues for VS 2017 Core 1.1.* projects.
Hi @dannythomas13,
It could be done within the next few weeks if we get a significant amount of people voting on this issue or best if someone submits a PR. Those things help push the item up our backlog queue.
Thanks @Jericho!
It looks like the fix is to reference System.Net.Http 4.3.1. I’ll give it a try.