Q:

SendGrid not found in HTTPTrigger function

I'm trying to create an Azure Function that will be trigerred by HTTP using VSCode in a macOS. 
Using official documentation, I successfully create an HTTP Trigered azure function in my local machine. 
Now I want to send a email during this function, but when I add a senGrid reference, I got a compilation error :

The following 1 functions are in error:
  [15/01/2018 21:51:12] ResetPasswordSendEmail: C# compilation service error: Could not load file or assembly 'SendGrid, Culture=neutral, PublicKeyToken=null'.  The system cannot find the file specified. 
  [15/01/2018 21:51:12] .  Could not load file or assembly 'SendGrid, Culture=neutral, PublicKeyToken=null'.  The system cannot find the file specified. 

The azure function : 
#r "SendGrid"
#r "Newtonsoft. Json"

using System. Net;
using Microsoft. AspNetCore. Mvc;
using Microsoft. Extensions. Primitives;
using Newtonsoft. Json;
using SendGrid. Helpers. Mail;

public static IActionResult Run(HttpRequest req, TraceWriter log, out Mail message)
{
    log. Info("C# HTTP trigger function processed a request."); 

    string requestBody = new StreamReader(req. Body).ReadToEnd();
    dynamic data = JsonConvert. DeserializeObject(requestBody);
    string email = data.email;
    string password = data.password;

    message = new Mail
    {        
        Subject = "Azure news"          
    };

    bool isOk = ! string. IsNullOrEmpty(email) && ! string. IsNullOrEmpty(password);

    return isOk ?  req. CreateResponse(HttpStatusCode. OK) : req. CreateResponse(HttpStatusCode. BadRequest, "EmailError");
}

The function json : 
{
    "disabled": false,
    "bindings": [{
            "authLevel": "function",
            "name": "req",
            "type": "httpTrigger",
            "direction": "in"
        },
        {
            "name": "message",
            "type": "sendGrid",
            "direction": "out",
            "apiKey": "AzureWebJobsSendGridApiKey"
        },
        {
            "name": "$return",
            "type": "http",
            "direction": "out"
        }
    ]
}

I want to keep the code at the same place and not have the azure functions outside code management (GIT). 
If somebody knows how to solve my issue, please help :D

A:

Since you are developing locally on a Mac, you are probably using v2 "core" version of func CLI tool. 
Navigate to your project root folder (where host.json is) and execute the following command:
func extensions install -p Microsoft. Azure. WebJobs. Extensions. SendGrid -v 3.0.0-beta4

This will add SendGrid binaries to bin folder of your Function App. 
Then, your script seems to be a mix of v1 and v2 functions.  For example, CreateResponse() doesn't belong to HttpRequest and Mail class is not in SendGrid assembly.  Here is a very simplistic example of sending a mail from HTTP function:
public static IActionResult Run(HttpRequest req, TraceWriter log, out SendGridMessage message)
{
    log. Info("C# HTTP trigger function processed a request."); 

    message = new SendGridMessage();
    message.AddTo("you@gmail.com");
    message. AddContent("text/html", "Test body");
    message. SetFrom(new EmailAddress("test@test.com"));
    message. SetSubject("Subject");

    return new OkObjectResult("OK");
}

