azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

No value was provided for parameter 'log' in Functions.RenderSwaggerUI

Open johnholliday opened this issue 3 years ago • 4 comments

Describe the issue Using dependency injection, getting exception in method 'Functions.RenderSwaggerUI' when attempting to display the Swagger UI page.

To Reproduce Steps to reproduce the behavior:

  1. Create an Azure Functions project including Microsoft.Azure.WebJobs.Extensions.OpenApi, and Microsoft.Extendions.Logging packages.
  2. Add a derived FunctionsStartup method with 'builder.Services.AddLogging()' as the first statement.
  3. Add 'ILogger<T> log' parameters as required to any HttpTrigger class constructors.
  4. Compile and execute the project, copying the 'http://localhost:/api/swagger/ui' endpoint into a new browser window.
  5. See the following errors in the debug console:
Executed 'Functions.RenderSwaggerUI' (Failed, Id=69e04003-c2a6-4fdb-aff6-e8266acf89dd, Duration=269ms)

System.Private.CoreLib: Exception while executing function: Functions.RenderSwaggerUI.
Microsoft.Azure.WebJobs.Host: Exception binding parameter 'log'.
Microsoft.Azure.WebJobs.Host: No value was provided for parameter 'log'.

Expected behavior Browser should display the generated Swagger UI.

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

  • OS: Windows 11 Version 22H2 (Build 22623.1028)
  • Browser Edge
  • Version 108.0.1462.54 (Official build) (64-bit)

johnholliday avatar Jan 01 '23 19:01 johnholliday

@johnholliday Thanks for the issue. Basically, it's more Azure Functions core runtime question, though. Two questions:

  1. Is there a specific reason that you add builder.Services.AddLogging()? The ILogger instance is added by default.
  2. Have you tried to modify host.json to display more detailed logs on your terminal?

justinyoo avatar Jan 30 '23 13:01 justinyoo

Thanks for responding. I tried removing the AddLogging statement - same result. I’ll increase verbosity and get back to you.

Excellent work, by the way.


From: Justin Yoo @.> Sent: Monday, January 30, 2023 8:32:56 AM To: Azure/azure-functions-openapi-extension @.> Cc: John Holliday @.>; Mention @.> Subject: Re: [Azure/azure-functions-openapi-extension] No value was provided for parameter 'log' in Functions.RenderSwaggerUI (Issue #529)

@johnhollidayhttps://github.com/johnholliday Thanks for the issue. Basically, it's more Azure Functions core runtime question, though. Two questions:

  1. Is there a specific reason that you add builder.Services.AddLogging()? The ILogger instance is added by default.
  2. Have you tried to modify host.json to display more detailed logs on your terminal?

— Reply to this email directly, view it on GitHubhttps://github.com/Azure/azure-functions-openapi-extension/issues/529#issuecomment-1408639403, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABIMPXCN2DFHKXIISEKLG6LWU67IRANCNFSM6AAAAAATOIPBNI. You are receiving this because you were mentioned.Message ID: @.***>

johnholliday avatar Jan 30 '23 14:01 johnholliday

I removed builder.Services.AddLogging() and also increased the log verbosity to 'Trace'. No change in behavior and no additional information is provided. Clicking the /api/swagger/ui endpoint gives this:

[2023-01-31T16:54:33.229Z] Host lock lease acquired by instance ID '000000000000000000000000000B7C7E'.
[2023-01-31T16:54:33.276Z] FUNCTIONS_WORKER_RUNTIME=dotnet. Will shutdown all the worker channels that started in placeholder mode
[2023-01-31T16:54:41.344Z] Executing HTTP request: {
[2023-01-31T16:54:41.346Z]   requestId: "94d748b7-9dfa-433e-9488-cb7cea6c56cd",
[2023-01-31T16:54:41.347Z]   method: "GET",
[2023-01-31T16:54:41.347Z]   userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70",
[2023-01-31T16:54:41.348Z]   uri: "/api/swagger/ui"
[2023-01-31T16:54:41.348Z] }
[2023-01-31T16:54:41.486Z] Request successfully matched the route with name 'RenderSwaggerUI' and template 'api/swagger/ui'
[2023-01-31T16:54:41.608Z] Executing 'Functions.RenderSwaggerUI' (Reason='This function was programmatically called via the host APIs.', Id=c98c3966-a4aa-4e82-8499-35e060c1352c)
[2023-01-31T16:54:41.799Z] Executed 'Functions.RenderSwaggerUI' (Failed, Id=c98c3966-a4aa-4e82-8499-35e060c1352c, Duration=274ms)
[2023-01-31T16:54:41.801Z] System.Private.CoreLib: Exception while executing function: Functions.RenderSwaggerUI. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'log'. Microsoft.Azure.WebJobs.Host: No value was provided for parameter 'log'.
[2023-01-31T16:54:41.849Z] Executed HTTP request: {
[2023-01-31T16:54:41.850Z]   requestId: "94d748b7-9dfa-433e-9488-cb7cea6c56cd",
[2023-01-31T16:54:41.851Z]   identities: "",
[2023-01-31T16:54:41.851Z]   status: "500",
[2023-01-31T16:54:41.852Z]   duration: "503"
[2023-01-31T16:54:41.852Z] }

For reference, here is the Startup code:

using AutoFixture;
using my.api.Configurations;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;

[assembly: FunctionsStartup(typeof(my.api.Startup))]

namespace my.api
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services
                .AddSingleton<Fixture>(new Fixture())
                .AddSingleton<IOpenApiConfigurationOptions>(_ =>
                {
                    return new MyOpenApiConfigurationOptions();
                })
                .AddSingleton<IOpenApiHttpTriggerAuthorization>(_ =>
                {
                    return new MyOpenApiHttpTriggerAuthorization();
                })
                .AddSingleton<IOpenApiCustomUIOptions>(_ =>
                {
                    var assembly = Assembly.GetExecutingAssembly();
                    return new MyOpenApiCustomUIOptions(assembly);
                });
        }
    }
}

johnholliday avatar Jan 31 '23 17:01 johnholliday

Any additional thoughts? I'm struggling to get this to work. Just created a separate issue (stack overflow) when displaying the page. Not sure where to turn for help.

johnholliday avatar May 09 '23 01:05 johnholliday