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

Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore and OpenApi extension #617

Open
safigi opened this issue Sep 22, 2023 · 5 comments

Comments

@safigi
Copy link

safigi commented Sep 22, 2023

Describe the issue
When I create a new Function App dotnet core 6.0 Isolated app and I am using the following nuget package:
Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore
and I am changing in the Program.cs this line:
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(worker => worker.UseNewtonsoftJson())
.Build();
to this
var host = new HostBuilder()
.ConfigureFunctionsWebApplication(worker => worker.UseNewtonsoftJson())
.Build();
, and I am trying to open the URL openapi UI I don't get any data.

To Reproduce
Steps to reproduce the behavior:
project attached to the report.

Expected behavior
I would like to use openapi extension with Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore nuget package.

Screenshots

Environment (please complete the following information, if applicable):

  • OS: Windows
  • Any browser
  • Version 1.5.1

Additional context

FunctionApp1.zip

@safigi safigi changed the title Bug report, feature request or other request Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore and OpenApi extension Sep 22, 2023
@HalinSky
Copy link

We are also encountering the same issue.

@Judas1337
Copy link

Judas1337 commented Oct 31, 2023

Edit: after checking how ...Http.AspNetCore returns errors for how HttpRequestData.Url is handled (it has thrown a UriFormatException), I found that the currently latest commit (Azure/azure-functions-dotnet-worker@bf56b37) might attempting to solve this issue.

We have also been dealing with the what could be the same problem for 2 days now. When going to "http://localhost:{port}/api/swagger.json" or "/api/swagger/ui" we get the error message below. It states One or more errors occurred. (Invalid URI: The URI is empty.).

Our best guess is that it's due to ConfigureAspNetCoreIntegration in https://github.com/Azure/azure-functions-dotnet-worker/blob/main/extensions/Worker.Extensions.Http.AspNetCore/src/FunctionsHostBuilderExtensions.cs
Here it's stated webBuilder.UseUrls(HttpUriProvider.HttpUriString); and HttpUriProvider is implemented as a string backed by a Lazy Uri in https://github.com/Azure/azure-functions-dotnet-worker/blob/main/extensions/Worker.Extensions.Http.AspNetCore/src/HttpUriProvider.cs
But we actually do not know what Uri is supposed to be read at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.HttpRequestObject..ctor. https://github.com/Azure/azure-functions-openapi-extension/blob/main/src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/HttpRequestObject.cs

The open api generation actually works fine if I don't use ConfigureFunctionsWebApplication and instead uses ConfigureFunctionsWorkerDefaults but this contradicts with what is stated here: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#aspnet-core-integration

[2023-10-31T14:42:56.448Z] swagger.json was requested.
[2023-10-31T14:42:56.490Z] Function 'RenderSwaggerDocument', Invocation id 'c21663e9-7129-4b63-a9b7-8c85dd259aa6': An exception was thrown by the invocation.
[2023-10-31T14:42:56.492Z] Result: Function 'RenderSwaggerDocument', Invocation id 'c21663e9-7129-4b63-a9b7-8c85dd259aa6': An exception was thrown by the invocation.
Exception: System.AggregateException: One or more errors occurred. (Invalid URI: The URI is empty.)
[2023-10-31T14:42:56.493Z]  ---> System.UriFormatException: Invalid URI: The URI is empty.
[2023-10-31T14:42:56.493Z]    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
[2023-10-31T14:42:56.494Z]    at System.Uri..ctor(String uriString)
[2023-10-31T14:42:56.495Z]    at Microsoft.Azure.Functions.Worker.GrpcHttpRequestData.get_Url() in D:\a\_work\1\s\src\DotNetWorker.Grpc\Http\GrpcHttpRequestData.cs:line 101
[2023-10-31T14:42:56.496Z]    at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.HttpRequestObject..ctor(HttpRequestData req)
[2023-10-31T14:42:56.497Z]    at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Functions.OpenApiTriggerFunction.RenderSwaggerDocument(HttpRequestData req, String extension, FunctionContext ctx)
[2023-10-31T14:42:56.498Z]    at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.DefaultOpenApiHttpTrigger.RenderSwaggerDocument(HttpRequestData req, String extension, FunctionContext ctx)
[2023-10-31T14:42:56.499Z]    --- End of inner exception stack trace ---
[2023-10-31T14:42:56.501Z]    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2023-10-31T14:42:56.502Z]    at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
[2023-10-31T14:42:56.503Z]    at System.Threading.Tasks.Task1.get_Result()
[2023-10-31T14:42:56.504Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker2.<>c.<InvokeAsync>b__6_0(Task1 t) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 32
[2023-10-31T14:42:56.505Z]    at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
[2023-10-31T14:42:56.506Z]    at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
[2023-10-31T14:42:56.506Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-10-31T14:42:56.507Z] --- End of stack trace from previous location ---
[2023-10-31T14:42:56.508Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-10-31T14:42:56.508Z]    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
[2023-10-31T14:42:56.509Z] --- End of stack trace from previous location ---
[2023-10-31T14:42:56.510Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 45
[2023-10-31T14:42:56.515Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-10-31T14:42:56.516Z]    at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 48
[2023-10-31T14:42:56.517Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77
Stack:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2023-10-31T14:42:56.518Z]    at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
[2023-10-31T14:42:56.521Z]    at System.Threading.Tasks.Task1.get_Result()
[2023-10-31T14:42:56.522Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker2.<>c.<InvokeAsync>b__6_0(Task1 t) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 32
[2023-10-31T14:42:56.523Z]    at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
[2023-10-31T14:42:56.523Z]    at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
[2023-10-31T14:42:56.524Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-10-31T14:42:56.525Z] --- End of stack trace from previous location ---
[2023-10-31T14:42:56.525Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-10-31T14:42:56.528Z]    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
[2023-10-31T14:42:56.529Z] --- End of stack trace from previous location ---
[2023-10-31T14:42:56.531Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 45
[2023-10-31T14:42:56.535Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-10-31T14:42:56.539Z]    at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 48

[2023-10-31T14:42:56.540Z] Executed 'Functions.RenderSwaggerDocument' (Failed, Id=c21663e9-7129-4b63-a9b7-8c85dd259aa6, Duration=400ms)
[2023-10-31T14:42:56.541Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77.
[2023-10-31T14:42:56.544Z] System.Private.CoreLib: Exception while executing function: Functions.RenderSwaggerDocument. System.Private.CoreLib: Result: Failure
Exception: System.AggregateException: One or more errors occurred. (Invalid URI: The URI is empty.)
[2023-10-31T14:42:56.546Z]  ---> System.UriFormatException: Invalid URI: The URI is empty.
[2023-10-31T14:42:56.547Z]    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
[2023-10-31T14:42:56.547Z]    at System.Uri..ctor(String uriString)
[2023-10-31T14:42:56.548Z]    at Microsoft.Azure.Functions.Worker.GrpcHttpRequestData.get_Url() in D:\a\_work\1\s\src\DotNetWorker.Grpc\Http\GrpcHttpRequestData.cs:line 101
[2023-10-31T14:42:56.549Z]    at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.HttpRequestObject..ctor(HttpRequestData req)
[2023-10-31T14:42:56.549Z]    at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Functions.OpenApiTriggerFunction.RenderSwaggerDocument(HttpRequestData req, String extension, FunctionContext ctx)
[2023-10-31T14:42:56.550Z]    at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.DefaultOpenApiHttpTrigger.RenderSwaggerDocument(HttpRequestData req, String extension, FunctionContext ctx)
[2023-10-31T14:42:56.551Z]    --- End of inner exception stack trace ---
[2023-10-31T14:42:56.552Z]    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2023-10-31T14:42:56.552Z]    at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
[2023-10-31T14:42:56.553Z]    at System.Threading.Tasks.Task1.get_Result()
[2023-10-31T14:42:56.553Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker2.<>c.<InvokeAsync>b__6_0(Task1 t) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 32
[2023-10-31T14:42:56.554Z]    at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
[2023-10-31T14:42:56.555Z]    at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
[2023-10-31T14:42:56.556Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-10-31T14:42:56.558Z] --- End of stack trace from previous location ---
[2023-10-31T14:42:56.560Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-10-31T14:42:56.560Z]    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
[2023-10-31T14:42:56.561Z] --- End of stack trace from previous location ---
[2023-10-31T14:42:56.562Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 45
[2023-10-31T14:42:56.563Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-10-31T14:42:56.567Z]    at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 48
[2023-10-31T14:42:56.568Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77
[2023-10-31T14:42:56.569Z]    at Microsoft.Azure.Functions.Worker.Handlers.InvocationHandler.InvokeAsync(InvocationRequest request) in D:\a\_work\1\s\src\DotNetWorker.Grpc\Handlers\InvocationHandler.cs:line 88
Stack:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2023-10-31T14:42:56.570Z]    at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
[2023-10-31T14:42:56.570Z]    at System.Threading.Tasks.Task1.get_Result()
[2023-10-31T14:42:56.571Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker2.<>c.<InvokeAsync>b__6_0(Task1 t) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 32
[2023-10-31T14:42:56.575Z]    at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
[2023-10-31T14:42:56.576Z]    at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
[2023-10-31T14:42:56.577Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-10-31T14:42:56.578Z] --- End of stack trace from previous location ---
[2023-10-31T14:42:56.579Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-10-31T14:42:56.580Z]    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
[2023-10-31T14:42:56.580Z] --- End of stack trace from previous location ---
[2023-10-31T14:42:56.581Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 45
[2023-10-31T14:42:56.582Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-10-31T14:42:56.582Z]    at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 48
[2023-10-31T14:42:56.583Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77
[2023-10-31T14:42:56.584Z]    at Microsoft.Azure.Functions.Worker.Handlers.InvocationHandler.InvokeAsync(InvocationRequest request) in D:\a\_work\1\s\src\DotNetWorker.Grpc\Handlers\InvocationHandler.cs:line 88```

@olegrotar
Copy link

+1. Also having this issue

@MohdmM01
Copy link

I am also having this issue with Open API extension when using ASP.Net core integration for Isolated Process Functions.

@ValeNaldi
Copy link

+1 for the same issue. Any workaround?

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

6 participants