HttpRequestMessageExtensions not being found at run-time in Azure Function

前端 未结 4 1392
忘了有多久
忘了有多久 2021-01-02 00:42

I\'ve got an Azure Function app that creates a precompiled DLL (so it uses normal .cs files, not the older .csx method, pre-VS2017). Previously, it was targeting .Net Framew

相关标签:
4条回答
  • 2021-01-02 01:23

    I also tested it on my side. The issue is related to the latest version of System.Net.Http assembly(4.3.2). If I don't install this package manually or install the earlier versions(4.3.1/4.3.0), the application could work fine.

    The CreateResponse method is a extension method which is written in System.Web.Http assembly(version 5.2.3). It seem that it is not compatible with the latest version of System.Net.Http. Please could just skip the error by using the earlier version of System.Net.Http and you can also submit this issue to Microsoft using follow channel.

    https://connect.microsoft.com/VisualStudio/Feedback

    Interesting. For me, if I got above version 4.0.0 (including 4.1.1 or 4.3.1) I still get the same problem of not finding those extension methods.

    The assembly might not be updated during you change the package version. From the bin\Debug\net47 folder, we could check the current assembly version we used.

    If the modified date of assembly is 2/9/2017, the package version is 4.3.1. If the modified date of assembly is 4/19/2017, the package version is 4.3.2. If the assembly is not the latest version, it could work fine on my side.

    In addition, Microsoft.Asp.Net.WebApi.Client package is installed by default when creating an Azure function. System.Net.Http is one of its dependencies. So we don't need to install the System.Net.Http package manually. When running our application, NuGet will choose a right version of System.Net.Http for our application.

    0 讨论(0)
  • 2021-01-02 01:23

    Using @Aaron-Newton's insight, I identified that my issue was due to my Azure Functions project referencing a .Net Standard 2.0 class library. I switched it to .Net Framework 4.6 and it started working again. Seems like this is a bug in the Functions tooling.

    I've filed a bug with the Functions team here: https://github.com/Azure/Azure-Functions/issues/477

    0 讨论(0)
  • 2021-01-02 01:25

    I had the same issue running my Azure Function locally and eventually tracked it down to conflicting System.Net.Http assemblies. I created my Azure function from a blank ASP.NET Web App and initially pulled down the System.Net.Http NuGet package to use within the project. I also pulled down the Microsoft.AspNet.WebApi.Client for use within the project. It did not matter which version of System.Net.Http I tried my project would compile but fail when the request was made.

    Eventually, I removed packages I had downloaded, cleaned the build folder and added just the Microsoft.AspNet.WebApi.Client. I noticed that this automatically referenced the System.Net.Http on my machine for my version of the .NET Framework. (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework). This compiled successfully and I was able to make requests to the function without any exceptions.

    0 讨论(0)
  • 2021-01-02 01:35

    I had the same issue. I spent quite a while to fix this problem.

    The cause is that the Azure Functions project is refering to .Net Standard Library with version higher than 1.4.

    Bringing down your .Net Standard version to 1.4 or lower would fix the problem.

    But this is defintely a bug with Azure Functions SDK. They should fix it.

    https://github.com/Azure/azure-webjobs-sdk-script/issues/980

    https://github.com/Azure/Azure-Functions/issues/477

    0 讨论(0)
提交回复
热议问题