2

I'm having quite a lot of trouble with the System.Net.Http libraries when using Azure Functions. If I create a brand new httptrigger Function in the portal, it works fine. However, I want to use my own precompiled assembly. When I do this, I get all sorts of issues.

One symptom I'm seeing is that the HttpRequestMessage that gets passed in has no details in it. RequestUri is empty, plus any of the other properties - eg. headers, etc. Note that the parameter is not null - it just seems to have not been populated with anything.

Another symptom is that when it tries to call GetQueryNameValuePairs, it fails saying:

Exception while executing function: Functions.WebHookSync. mscorlib: Exception has been thrown by the target of an invocation. MyFunctionName.Functions: Method not found: 'System.Collections.Generic.IEnumerable`1<System.Collections.Generic.KeyValuePair`2<System.String,System.String>> System.Net.Http.HttpRequestMessageExtensions.GetQueryNameValuePairs(System.Net.Http.HttpRequestMessage)'.

Below is the contents of my .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="2.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyOtherAssembly\MyOtherAssembly.csproj" />
  </ItemGroup>
</Project>

The Microsoft.AspNet.WebApi.Core nuget package contains the system.net.http libraries. I've tried various combinations of the different nuget packages that relate to this - but having no luck.

Does anyone know what packages I should be using to get this to work?

2 Answers 2

1

I had issues with MissingMethodExceptions in System.Net.Http. What worked for me was the following reference:

<package id="System.Net.Http" version="4.0.0" targetFramework="net461" />
Sign up to request clarification or add additional context in comments.

1 Comment

This seems to work now. Although unfortunately, that doesn't include the GetQueryNameValuePairs method, so I'm just using a regex to parse the query string. Also had to downgrade all my other libraries to 46 (from .net core) as there then became chain dependencies errors. Hopefully, Azure Functions will support .NET Core soon (github.com/Azure/Azure-Functions/issues/98).
1

Here are the System.Net.Http references in the functions runtime.

I suggest that you add try to add them directly to your precompiled project.

Here are a couple precompiled function samples that have http triggers to try as well (1,2).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.