azure-functions-openapi-extension: BUG: Object reference not set.... .net 6 functions

Describe the issue When using this library in a new Azure Functions project (.net6, runtime V4) it works locally but not on Azure.

Object reference not set to an instance of an object.

To Reproduce

  1. Create new Azure functions project with .Net 6
  2. Add a new project without dependencies and reference it in your functions project
  3. Deploy to Azure
  4. Call /api/swagger.json

Expected behavior I expect that swagger would just work like it does locally.

Screenshots

image

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

  • OS: Azure (Windows Service plan, FUNCTIONS_EXTENSION_VERSION = ~4, FUNCTIONS_WORKER_RUNTIME = dotnet)
  • Version 1.0.0 (nuget)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Hi @justinyoo - I can confirm that even after updating to v1.3.0 of the Microsoft.Azure.WebJobs.Extensions.OpenApi package I’m still seeing the following error when my function app references a net6.0 class library which has no dependencies:

Object reference not set to an instance of an object.

   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiHttpTriggerContext.<>c.<GetRuntimeFilenameAsync>b__43_1(KeyValuePair`2 target)
   at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value, IEqualityComparer`1 comparer)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiHttpTriggerContext.<>c__DisplayClass43_0.<GetRuntimeFilenameAsync>b__3(<>f__AnonymousType0`3 r)
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiHttpTriggerContext.GetRuntimeFilenameAsync(String functionAppDirectory)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiHttpTriggerContext.SetApplicationAssemblyAsync(String functionAppDirectory, Boolean appendBin)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions.OpenApiHttpTriggerContextExtensions.AuthorizeAsync(Task`1 context, IHttpRequestDataObject req)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctionProvider.RenderSwaggerUI(HttpRequest req, ExecutionContext ctx, ILogger log)

I had the same problem and I solved it based on an old issue. Where the person indicated that all projects on their system must have at least one dependency. I added a random package to a project of mine that didn’t have any and it started working.

Since the comments above provided a work-around, this is what triggers the error:

  1. Create a new azure Functions app with OpenApi support
  2. Add an additional project, WITHOUT dependencies.
  3. Add the second project as a project dependency to the functions project.
  4. The swagger ui should still appear locally, and the endpoint from the template should be in the swagger ui.
  5. Publish to Azure and it stops working, with the error above in the ligging.

Bizarre issue. The “at least one dependency per project” workaround worked for me as well.

I am having the exact same issue (.net6, runtime V4). It works just fine locally but not on Azure.