Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method not found: System.Net.Http.HttpRequestMessageExtensions.CreateResponse when referencing .Net Standard Project #477

Closed
kensykora opened this issue Sep 2, 2017 · 17 comments
Assignees

Comments

@kensykora
Copy link

If an Azure Functions project which uses Http triggers references a .Net Standard class library, the functions tooling throws Method not found exceptions.

Example Project: https://github.com/kensykora/musicbot-backend/tree/98eb1fb43498681c7a80381d4dcc46c1c2c011c1 (use this specific commit, as I've worked around it, see below)

Related Stack Overflow Post: https://stackoverflow.com/questions/45271133/httprequestmessageextensions-not-being-found-at-run-time-in-azure-function#comment78861154_45273862

Tooling / Versions:

  • Windows 10.0.15063
  • VS 2017 15.4.0 Preview 1.0
  • Azure Functions and Web jobs Tools 15.0.30812.0
  • .Net Core 2.0

Steps to reproduce:

  1. Create a new solution with a function app.
  2. Create a function with an Http Trigger
  3. Run the Solution, hit the function with your browser. Observe no errors.
  4. Add a new .Net standard class library 2.0 project to the solution
  5. Add a reference to the class library project in the function app
  6. Re-run the function app and hit the function with your browser:

Expected: No Errors
Actual: HttpMissingMethodException:

Error from my local functions CLI tool:

{
    "id": "eac68af9-7995-458c-af37-6f13912394d7",
    "requestId": "c636de68-7cd5-4e69-8e27-8054f1d3acb5",
    "statusCode": 500,
    "errorCode": 0,
    "message": "Exception while executing function: PlaySong -> Method not found: 'System.Net.Http.HttpResponseMessage System.Net.Http.HttpRequestMessageExtensions.CreateResponse(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, !!0)'.",
    "errorDetails": "Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: PlaySong ---> System.MissingMethodException : Method not found: 'System.Net.Http.HttpResponseMessage System.Net.Http.HttpRequestMessageExtensions.CreateResponse(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, !!0)'.   at async MusicBot.Functions.PlaySong.Run(HttpRequestMessage req,TraceWriter log)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at MusicBot.Functions.PlaySong.Run(HttpRequestMessage req,TraceWriter log)
   at lambda_method(Closure ,PlaySong ,Object[] )
   at Microsoft.Azure.WebJobs.Host.Executors.TaskMethodInvoker`2.InvokeAsync(TReflected instance,Object[] arguments)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync[TReflected,TReturnValue](Object[] arguments)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,ILogger logger,CancellationTokenSource functionCancellationTokenSource)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) 
   End of inner exception
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken)
   at Microsoft.Azure.WebJobs.Host.Executors.ExceptionDispatchInfoDelayedException.Throw()
   at async Microsoft.Azure.WebJobs.JobHost.CallAsync(??)
   at async Microsoft.Azure.WebJobs.Script.ScriptHost.CallAsync(String method,Dictionary`2 arguments,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager.HandleRequestAsync(FunctionDescriptor function,HttpRequestMessage request,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ProcessRequestAsync(HttpRequestMessage request,FunctionDescriptor function,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.<>c__DisplayClass3_0.<ExecuteAsync>b__0(??)
   at async Microsoft.Azure.WebJobs.Extensions.Http.HttpRequestManager.ProcessRequestAsync(HttpRequestMessage request,Func`3 processRequestHandler,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)
   at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.SystemTraceHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.WebScriptHostHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at async System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)"
}

Workaround: Change the class library project to .Net Framework

@LTsLlama
Copy link

LTsLlama commented Sep 3, 2017

We have the same problem and cannot use the workaround as we are dependent on https://github.com/microsoftgraph/msgraph-sdk-dotnet which is dependant on System.Net 4.3.2

@GeekyEggo
Copy link

I'm having a similar issue; after referencing a .NET standard class library, I'm unable to even trigger the function in development, with the function resulting in the following exception:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: SlackWebHooks ---> System.InvalidOperationException : Exception binding parameter 'req' ---> Newtonsoft.Json.JsonReaderException : Unexpected character encountered while parsing number: W. Path '', line 1, position 6.
   at Newtonsoft.Json.JsonTextReader.ReadNumberIntoBuffer()
   at Newtonsoft.Json.JsonTextReader.ParseNumber(ReadType readType)
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader,JsonContract contract,Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader,Type objectType,Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader,Type objectType)
   at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.ReadFromStream(Type type,Stream readStream,Encoding effectiveEncoding,IFormatterLogger formatterLogger)
   at System.Net.Http.Formatting.JsonMediaTypeFormatter.ReadFromStream(Type type,Stream readStream,Encoding effectiveEncoding,IFormatterLogger formatterLogger)
   at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.ReadFromStream(Type type,Stream readStream,HttpContent content,IFormatterLogger formatterLogger)
   at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.ReadFromStreamAsync(Type type,Stream readStream,HttpContent content,IFormatterLogger formatterLogger)
   at async System.Net.Http.HttpContentExtensions.ReadAsAsyncCore[T](HttpContent content,Type type,IFormatterLogger formatterLogger,MediaTypeFormatter formatter,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider.HttpTriggerBinding.CreateUserTypeValueProvider(HttpRequestMessage request,String invokeString)
   at async Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider.HttpTriggerBinding.BindAsync(Object value,ValueBindingContext context)
   at async Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.BindCoreAsync[TTriggerValue](ValueBindingContext context,Object value,IDictionary`2 parameters) 
   End of inner exception
   at Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw()
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,ILogger logger,CancellationTokenSource functionCancellationTokenSource)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) 
   End of inner exception
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken)
   at Microsoft.Azure.WebJobs.Host.Executors.ExceptionDispatchInfoDelayedException.Throw()
   at async Microsoft.Azure.WebJobs.JobHost.CallAsync(??)
   at async Microsoft.Azure.WebJobs.Script.ScriptHost.CallAsync(String method,Dictionary`2 arguments,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager.HandleRequestAsync(FunctionDescriptor function,HttpRequestMessage request,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ProcessRequestAsync(HttpRequestMessage request,FunctionDescriptor function,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.<>c__DisplayClass3_0.<ExecuteAsync>b__0(??)
   at async Microsoft.Azure.WebJobs.Extensions.Http.HttpRequestManager.ProcessRequestAsync(HttpRequestMessage request,Func`3 processRequestHandler,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)
   at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.SystemTraceHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.WebScriptHostHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at async System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)"

@svickers
Copy link

svickers commented Sep 5, 2017

Same issue and can't use the workaround as one of our assemblies depends on System.Net.Http 4.3.2.

@LTsLlama
Copy link

LTsLlama commented Sep 7, 2017

After installing Azure Functions and Web Jobs Tools 15.0.30901.0 my error have changed to: "Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=4.0.40306.1554, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."

Is there a workaround for this?

@elexisvenator
Copy link

Also experiencing the same issue. Exact same steps to reproduce but the issue occurs using the currently stable tooling, not just the previews.

My Tooling:

  • Visual Studio Enterprise 15.3.3
  • .Net 4.7.02046
  • Azure Functions and Web Jobs Tools 15.0.30728.0

My Project

  • Function app project's only nuget reference is Microsoft.NET.Sdk.Functions 1.0.2
  • Has a reference to a .net standard 2.0 class library in the same solution. That library has no additional references.

@paulbatum
Copy link
Member

Should be fixed by Azure/azure-functions-host@be779c7

Deployment is scheduled to start 9/13. Likely to complete globally by 9/20. You'll be required to update the azure functions core tools at that point. We'll update this issue with the exact version number once we have it.

Feel free to throw rocks at me here or on twitter (@paulbatum) if there is no update on this thread by 9/22.

StephenCleary added a commit to StephenClearyApps/DotNetApis that referenced this issue Sep 12, 2017
@zhenyu-siama
Copy link

I had the same issue. Azure Functions can not find the method.

I also tried to create the Response message with its own constructor. Using constructor allows Functions to debug, but the browser could not get any response.

@zhenyu-siama
Copy link

I spend quite a while to fix this problem.

It seems that Azure functions can not refer to .Net Standard Lib targeting .Net Standard Version higher than 1.4.

I hope they could fix this soon.

@paulbatum
Copy link
Member

The fix is going out a part of the 1.0.11232 release. Deployment is still in progress but its already fully done in North Central US, West US 2. Creating a new function app in one of these regions or restarting an existing one should be sufficient to get the update.

A core tools release with this change is still coming.

@paulbatum
Copy link
Member

Version 1.0.4 of Azure Functions Core Tools is out with this fix.

However VS currently has a bug where it does not autoupdate to the newest version of the tools. I recommend you follow the steps documented here for grabbing the latest tools and then configuring VS to use them.

The fix is now deployed to Azure globally so you should not run into any problems once you publish to the cloud. You may have to do a restart on your function app to make sure it picks up the updated runtime.

Please let us know if this does not resolve your issues with referencing .NET Standard 2.0 packages. Thanks for your patience!

@ewilsonambient
Copy link

I created a standard httptrigger function just today. Works fine until I add a project.json file with a dependency to Microsoft.Azure.Devices.Client 1.2.10. Then I get http errors during compilation: This is directly in the function editor on portal.azure.com.

project.json file:
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Azure.Devices.Client": "1.2.10"
}
}
}
}
Http Errors:

2017-09-21T19:44:14.167 run.csx(12,29): error CS1929: 'HttpContent' does not contain a definition for 'ReadAsAsync' and the best extension method overload 'HttpContentExtensions.ReadAsAsync(HttpContent)' requires a receiver of type 'HttpContent'
2017-09-21T19:44:14.167 run.csx(34,39): error CS0103: The name 'HttpStatusCode' does not exist in the current context
2017-09-21T19:44:14.167 run.csx(63,47): error CS0103: The name 'HttpStatusCode' does not exist in the current context

@elexisvenator
Copy link

@paulbatum This fix seems to have introduced a new .net Standard 2.0 error. Now, if you reference a .Net Standard2.0 project, and your functionapp uses an ILogger instead of a TraceWriter for logging, you will get the below error. Replacing the ILogger with the original TraceWriter will make the function work again, though this is undesirable for us.

On Australia Southeast, this error did not occur as recently as 32 hours ago. We first noticed this issue 24 hours ago.

{
  "id": "57bc9a4a-12c3-4889-852a-5e5734596229",
  "requestId": "0f29f931-245b-41d7-9c97-0e2bc6ab1e9e",
  "statusCode": 500,
  "errorCode": 0,
  "message": "'DataServiceFunction' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?"
}

@paulbatum
Copy link
Member

@ewilsonambient I do not believe that error is related to the change this thread is discussing. This is because I was still able to repro this error on an older versions of functions (specifically 1.0.11027) that does not have the fix discussed here.

I have not looked to closely, but as far as I know there is an incompatibility between Azure Functions and more recent versions of the Microsoft.Azure.Devices.Client NuGet in that it relies on binding redirects and Azure Functions does not support binding redirects currently. Try using version 1.0.17.

e.g.

{
"frameworks": {
    "net46":{
        "dependencies": {
            "Microsoft.Azure.Devices.Client": "1.0.17"            
                    }
                }
        }
}

If you wish to discuss further I suggest you file a new issue so we can keep this thread on topic. Thanks!

@paulbatum
Copy link
Member

@elexisvenator I'm having trouble reproducing this.

I made a new function app in VS, updated to our latest bits (https://www.nuget.org/packages/Microsoft.NET.Sdk.Functions/1.0.4 which includes updated dependencies), added a http trigger and changed the TraceWriter to ILogger and deployed to a new function app in Azure and confirmed that the function worked fine.

I then thought it might be related to function apps compiled against older bits so I downgraded to Microsoft.NET.Sdk.Functions/1.0.0, built and deployed and it still worked.

I looked at some of our logs and I can see the ILogger related error System.InvalidOperationException : Cannot bind parameter 'log' to type ILogger.. Our logs show a handful of other apps getting the same error.

If you can figure out a simplified repro that would be very helpful.

In the meantime... @brettsam, @fabiocav any ideas?

@elexisvenator
Copy link

@paulbatum I have done some more testing over the weekend and found that my issue is not with .Net Standard projects, but rather with manually referencing Microsoft.Extensions.Logging.Abstractions >1.1.1, either directly or via another nuget package as I was doing.

Microsoft.NET.Sdk.Functions 1.0.4 uses Abstractions v1.1.1 and upgrading that package to any higher issue seems to cause the issues.

I have a small repo here to test the issue with.

@elexisvenator
Copy link

@paulbatum related: #334

@fabiocav
Copy link
Member

@elexisvenator this is indeed an issue where a reference outside of our redirect range causes a type mismatch with the binding provider that supports ILogger, resulting in a binding failure.

We'll address this on the next release.

In the meantime, please target version 1.1.1 or lower.

Thank you for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants