Azure / azure-webjobs-sdk-extensions

Azure WebJobs SDK Extensions
MIT License
344 stars 206 forks source link

SendGrid Examples Doesn't Work #169

Closed markolbert closed 8 years ago

markolbert commented 8 years ago

I tried to follow the SendGrid examples, but the WebJob console app fails on startup, complaining about not being able to load v6.1 of the SendGridMail assembly. Unfortunately, that version of the assembly doesn't contain the SendGrid.Helpers.Mail namespace that the examples use.

I tried to work around the problem by installing the most recent version of SendGrid (8.0.5, as I recall), and putting the following in app.config:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="SendGridMail" publicKeyToken="2ae73662c35d80e4" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>

But that didn't work (same crash and error message on startup of the WebJob app).

How do I get the examples to work?

brettsam commented 8 years ago

There shouldn't be any references to 6.1 anywhere in the latest commits (I don't see any). My guess is that VS is loading an old version of the SendGrid assemblies that you had previously built.

Some things to try:

markolbert commented 8 years ago

I've never built any version of SendGrid; all I did was install it from the NuGet package manager, which I'm beginning to think installs an outdated version of the libraries.

I posted more information over on stackoverflow (http://stackoverflow.com/questions/40276104/webjob-not-loading-sendgridmail-assembly).

markolbert commented 8 years ago

I tried specifying a config parameter to UseSendGrid(), but the same exception about not being able to find the correct assembly gets thrown.

brettsam commented 8 years ago

Can you write out from scratch exactly what steps you're taking to run this? Example -- are you cloning the github repo and building it, or are you creating a new project and adding nuget references to Microsoft.Azure.WebJobs.Extensions.SendGrid?

Also, could you post the entire packages.config file from your console app?

markolbert commented 8 years ago

I have an existing console app WebJob project, built under Net 4.6, to which I initially added the SendGrid Extensions nuget package via the NuGet Package Manager. Based on advice over on stackoverflow, I then removed the nuget package and installed the required assemblies by editing project.json. In both cases UseSendGrid() throws the "can't find assembly" exception.

I don't have a packages.config file in the project. Here's the project.json file:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "publishOptions": {
    "include": [
      "run.cmd",
      "UploadProcessor.runtimeconfig.json"
    ]
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Concurrent": false,
      "System.GC.Server": false
    }
  },

  "dependencies": {
    "ConnellData": "1.0.0-*",
    "ConnellDBF": "1.0.0-*",
    "Microsoft.Azure.WebJobs": "1.1.2",
    "Microsoft.Azure.WebJobs.Core": "1.1.2",
    "Microsoft.Azure.WebJobs.Extensions.SendGrid": "1.0.1",
    "Microsoft.EntityFrameworkCore": "1.0.1",
    "Microsoft.Web.WebJobs.Publish": "1.0.12",
    "Microsoft.WindowsAzure.ConfigurationManager": "3.2.3",
    "Newtonsoft.Json": "9.0.1",
    "PDFsharp-MigraDoc-GDI": "1.50.4000-beta3b",
    "Sendgrid": "8.0.5",
    "SendGrid.CSharp.HTTP.Client": "3.0.0",
    "SendGrid.SmtpApi": "1.3.1",
    "Serilog": "2.3.0",
    "Serilog.Sinks.TextWriter": "2.0.0",
    "UploadFramework": "1.0.0-*",
    "WindowsAzure.Storage": "7.2.1",
    "Zen.Barcode.Rendering.Framework": "3.1.10729.1"
  },

  "frameworks": {
    "net46": {
      "frameworkAssemblies": {
        "System.Configuration": "4.0.0.0",
        "System.IO.Compression": "4.0.0.0"
      }
    }
  }
}
brettsam commented 8 years ago

I think this is the problem -- "Microsoft.Azure.WebJobs.Extensions.SendGrid": "1.0.1". That dependency won't work with SendGrid 8.0.5 because they significantly changed how you send mail with the v3 API (https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html).

If you want to use the latest-and-greatest, you can update your WebJobs dependencies to the latest from our 'nightly' builds on MyGet (https://github.com/Azure/azure-webjobs-sdk/wiki/%22Nightly%22-Builds). This is what the docs reflect.

If you want to stay with 1.0.1, you'll need to roll back SendGrid to version 6.1.0, which uses an older version of their model. And in that case, these docs will help: https://github.com/Azure/azure-webjobs-sdk-extensions/blob/07aab33ed5fb73a6e1de9e807c8a7e4dba1fc9c5/README.md#sendgrid.

markolbert commented 8 years ago

Which probably explains why I am currently able to send emails using the approach Tom suggested over on stackoverflow, which doesn't utilize the out parameter approach (i.e., it builds and sends the email within the method body).

Thanx for clarifying this. I wish the exception message was more helpful in pinning down the problem, but since it probably comes from deep in the bowels of .Net that's probably not possible.