Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when creating SendGridAPIClient #465

Closed
dannythomas13 opened this issue May 23, 2017 · 22 comments
Closed

Exception when creating SendGridAPIClient #465

dannythomas13 opened this issue May 23, 2017 · 22 comments
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: bug bug in the library

Comments

@dannythomas13
Copy link

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:
net461

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>
@thinkingserious thinkingserious added status: help wanted requesting help from the community type: question question directed at the library labels May 23, 2017
@thinkingserious
Copy link
Contributor

Hello @dannythomas13,

What version of Visual Studio are you using and on what OS?

With Best Regards,

Elmer

@dannythomas13
Copy link
Author

@thinkingserious thanks for getting back to me, I am using VS2017 Professional on Windows 7 64 bit

@ShurikEv
Copy link

I have same problem, but I am using VS2017 Enterprise on Windows 10 64 bit

@thinkingserious
Copy link
Contributor

Thanks for adding your voice to this issue. I've added your vote to this issue in our backlog to help increase its priority.

@dannythomas13
Copy link
Author

@ShurikEv I desperately need to be able to send emails from an azure app for a current project if you find another solution before this is resolved can you let me know please?

@thinkingserious
Copy link
Contributor

@dannythomas13 have you tried using the SendGrid addon within Azure?

@Jericho
Copy link

Jericho commented May 26, 2017

@dannythomas13 to work around the problem you are experiencing you could also consider StrongGrid

@thinkingserious
Copy link
Contributor

@Jericho, do have an idea on what the problem could be?

@Jericho
Copy link

Jericho commented May 29, 2017

@thinkingserious just a wild guess: the problem seems to be regarding a missing assembly called System.Diagnostics.DiagnosticSource, so maybe add it to your package?

@thinkingserious
Copy link
Contributor

Thanks @Jericho!

@dannythomas13,

Could you please try adding that assembly to your project to see if that resolves the issue?

Also, I could not replicate this on Visual Studio 2015, so I will get 2017 going to try and replicate there.

Thanks!

@dannythomas13
Copy link
Author

@Jericho @thinkingserious difficult for me as when i add reference to 4.0.0 i get lots of warning that i am downgrading from 4.3.0 which is required from all of the 1.1.* asp core libraries

@dannythomas13
Copy link
Author

@thinkingserious regarding the azure addon i assumed this is what i had but still needed to code to send messages? I was following this guide:
https://docs.microsoft.com/en-us/azure/app-service-web/sendgrid-dotnet-how-to-send-email
Is this not the correct appraoch?

@thinkingserious
Copy link
Contributor

Thanks @Jericho!

It looks like the fix is to reference System.Net.Http 4.3.1. I'll give it a try.

@thinkingserious
Copy link
Contributor

@dannythomas13,

That is the correct approach; however, it looks like we have to fix some dependency issues for VS 2017 Core 1.1.* projects.

@dannythomas13
Copy link
Author

@thinkingserious is this something that could be done within the next few weeks? If not is there a workaround?

@thinkingserious
Copy link
Contributor

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.

@dannythomas13
Copy link
Author

@thinkingserious Did this issue make the next release? :)

@thinkingserious
Copy link
Contributor

Hi @dannythomas13,

Unfortunately, this issue is still fairly low on our backlog. It can gain momentum with additional votes or a PR.

Thanks for checking in!

With Best Regards,

Elmer

@dannythomas13
Copy link
Author

Hi Elmer, do you have a public facing backlog so I can keep an eye on the priority of this issue please?

@thinkingserious
Copy link
Contributor

Hi @dannythomas13,

We do not right now, but I'm going to discuss this with my product manager today and see if we can come up with a better way to inform on our progress.

With Best Regards,

Elmer

@thinkingserious thinkingserious added difficulty: medium fix is medium in difficulty hacktoberfest labels Sep 30, 2017
@thinkingserious thinkingserious added type: bug bug in the library up-for-grabs and removed type: question question directed at the library labels Mar 1, 2018
@thinkingserious
Copy link
Contributor

Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

5 participants