azure-webjobs-sdk: Functions v2 HttpTrigger fails with Autofac resolution exceptions
Attempting to create a HttpTrigger-based Durable Function with an OrchestrationClient
input binding will fail when the HTTP endpoint is hit with an Autofac exception.
VS 2017 version: 15.5.2 VS 2017 Extension version: 15.0.31201.0 Microsoft.NET.Sdk.Functions version: 1.0.6
Repro steps
- Create a new Azure Function v2 project, with an HttpTrigger-based function
- Modify the function code as follows:
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using System.Net;
using System.Net.Http;
namespace AzureFunctions.Durable
{
public static class Orchestrator
{
[FunctionName("Orchestrator")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
return req.CreateResponse(HttpStatusCode.OK, @"return value");
}
}
}
- Hit F5
- Send a request to the endpoint
Expected behavior
The request is fielded and an OK result it sent back
Actual behavior
The Functions runtime errors out trying to resolve things from Autofac:
[1/4/2018 6:50:20 PM] Host lock lease acquired by instance ID '000000000000000000000000C0DDBD63'.
[1/4/2018 6:50:22 PM] Job host started
[1/4/2018 6:50:28 PM] Function started (Id=a5660c71-2983-4431-8f54-939bd99b6460)
[1/4/2018 6:50:28 PM] Executing 'Orchestrator' (Reason='This function was programmatically called via the host APIs.', Id=a5660c71-2983-4431-8f54-939bd99b6460)
[1/4/2018 6:50:29 PM] A ScriptHost error has occurred
[1/4/2018 6:50:29 PM] Exception while executing function: Orchestrator. Autofac: The requested service 'System.Net.Http.Formatting.IContentNegotiator' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
Workaround
Instead of using req.CreateResponse
, creating a new HttpResponseMessage
object like new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"return value") };
will alleviate the Autofac resolution errors… However, it’s not known what other impacts this lack of an ability to resolve types will have down the line, and req.CreateResponse
is the way we create responses from HttpRequestMessage
objects in Functions v1
Can’t use IActionResult
types due to #1491
Suspicions
I suspect this is a side-effect of the build warning we get currently with Azure Functions v2:
AzureFunctions.Durable.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Client 5.2.2' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 16 (12 by maintainers)
Replicated using
return req.CreateResponse(HttpStatusCode.OK, result);
Error: