0

Function app unable to run with null configuration error

Developed function in visual studio to read api response. It works fine when run locally, but doesnt work when publish as azure function app

Below is my entry function which is run on incoming http request:

public static async Task<Bolean> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)

expected to run fine.. error instead The request does not have an associated configuration object or the provided configuration was null.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
Gopal
  • 41
  • 1
  • 4
  • Could you share your code snippet please? – Md Farid Uddin Kiron May 20 '19 at 03:07
  • Have you referred to the suggestion mentioned here:https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook . Can you try this 'Route = TestFunction/{name}' in the code and in the Azure function settings in Data Factory, I used the Function Name = TestFunction/albany – SumanthMarigowda-MSFT May 20 '19 at 05:55

3 Answers3

0

System.InvalidOperationException: The request does not have an associated configuration object or the provided configuration was null.

When testing the request out side of a httpserver you need to give the request a HttpConfiguration.

To fix this we need to add a HttpConfiguration object through the Properties dictionary as below:

var configuration = new HttpConfiguration();
var request = new System.Net.Http.HttpRequestMessage();
req.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration;

For more details, you could refer to https://stackoverflow.com/a/44447349/

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Joey Cai
  • 18,968
  • 1
  • 20
  • 30
0

I had a similar issue. Posting this solution in case it helps anyone.

I added a vanilla Azure Function App project in Visual Studio and while it worked on my local machine, I kept receiving a 500 Internal Server error from the deployed Azure version.

The error response was the same when calling the Function using Postman OR when using the Code + Test section while POSTing a valid request body.

enter image description here

enter image description here

The associated Application Insights trace revealed the error details as: enter image description here

The solution that worked for me was changing the Runtime version (your Function App > Configuration > Function runtime settings > Runtime version) from the current default value of ~3 to ~1.

enter image description here

Changing this value triggered a restart of the Service within Azure and the 500 internal server error was resolved.

enter image description here

This How to target Azure Functions runtime versions learn.microsoft.com link has further details around this setting.

foxfuzz
  • 63
  • 1
  • 7
0

This can also be caused by a multiple versions of System.Web.Http being loaded, which you could verify using the modules window in Visual Studio:

screenshot of visual studio modules tab

One way this could happen is by referencing (or having dependencies that reference) any version of Microsoft.AspNet.WebApi.Core other than version 5.2.3 which is used by Azure Functions (v1).

A potential workaround is to force the version back by adding this to your project file (.csproj):

<!-- work around package version conflict with Azure Functions -->
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.3" NoWarn="NU1605" />
Fowl
  • 4,940
  • 2
  • 26
  • 43