I created a out of the box Azure Function App with an Azure Http Trigger. Which gave me the below code. All I have updated is I am converting the HttpRequest body into my Helper class.
Here is the code
public static class TriggerTest
{
[FunctionName("TriggerTest")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = new StreamReader(req.Body).ReadToEnd();
Helper data = JsonConvert.DeserializeObject<Helper>(requestBody);
name = name ?? data?.value;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}
public class Helper
{
public string value { get; set; }
}
When I attempt to run it compiles fine, but then the console is spammed with the below
A ScriptHost error has occured
System.Private.CoreLib: Exception while executing function: TriggerTest. TestingAzure.FunctionApp: Could not load file or assembly ‘Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’. Could not find or load a specific file (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly ‘Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’
All of the Nuget packages are referencing Newtonsoft 11.0.2 which is what the Microsoft.NET.Sdk.Functions referencing. The project is a .NET Standard 2.0 project. The Nuget packages I am referencing are
- Microsoft.ApplicationInsights v2.7.2
- Microsoft.Azure.WebJobs.Extensions v3.0.0.-beta8
- Microsoft.Azure.WebJobs.Extensions.Http v3.0.0-beta8
- Microsoft.Azure.WebJobs.ServiceBus v3.0.0.-beta5
- Microsoft-NET-Sdk-Functions v1.0.19 NETStandard,Library v2.0.3
- Newtonsoft.Json v11.0.2
I am running this locally and have not yet tested it up in Azure, however I need it to work locally for testing purposes.
Also the CLI which is downloaded from Visual Studio 2017 is 2.0.1-beta.25
Azure Functions and Web Jobs Tools for Visual Studio is Version 15.10.2009.0

