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

Missing dependencies in *.deps.json leads to Object reference not set to an instance of an object #302

Open
alexchiraples opened this issue Nov 1, 2021 · 4 comments

Comments

@alexchiraples
Copy link

alexchiraples commented Nov 1, 2021

I receive an object reference error if my function app references a project that has no dependencies.

To reproduce

  1. git clone https://github.com/justinyoo/azfunc-openapi-dotnet.git
  2. cd azfunc-openapi-dotnet
  3. dotnet new classlib -o domain
  4. cd Net60.FunctionApp.OutOfProc.Static
  5. dotnet add reference .\..\domain
  6. dotnet add package Microsoft.Azure.Functions.Worker
  7. dotnet add package Microsoft.Azure.Functions.Worker.Sdk
  8. dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Http
  9. dotnet add package Microsoft.Azure.Functions.Worker.Extensions.OpenApi --prerelease
  10. dotnet build (you will need to fix some missing reference errors)
  11. func start
  12. go to http://localhost:7071/api/swagger/ui

Error

Object reference not set to an instance of an object.

   at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.OpenApiHttpTriggerContext.<>c.<GetRuntimeFilenameAsync>b__42_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.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.OpenApiHttpTriggerContext.GetRuntimeFilenameAsync(String functionAppDirectory)
   at Microsoft.Azure.Functions.Worker.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.Functions.Worker.Extensions.OpenApi.Functions.OpenApiTriggerFunction.RenderSwaggerUI(HttpRequestData req, FunctionContext ctx)

Environment

Additional context
It seems to be related with #172 and fails if referenced project has no dependency in the *.deps.json file

@vincentbitter
Copy link
Contributor

vincentbitter commented Nov 5, 2021

I can confirm this issue. Suddenly ran into this issue too this week. Dependencies was always an empty list before and now it can be null. Maybe something has changed in .NET, Functions or Newtonsoft Json causing this issue. Anyhow, we should do a null-check on the .Dependencies to avoid this.

Quickfix I used for now, is to reference a random small NuGet project in the libraries that do not have any dependency.

@jormasyrja
Copy link

Using the in-process model, this happens to me only when deployed to Azure.

@Hjortsberg
Copy link

I can also confirm and reproduce, using in-process model, .Net Core 3.1 Function.
Referencing a project without dependencies causes this, and disappears when adding any NuGet as suggested by @vincentbitter solves it for the moment. :) Thanks for sharing your quick fix!

@DannyvdSluijs
Copy link
Contributor

DannyvdSluijs commented Jan 12, 2022

For the sake of adding more context to the issue: For me this popped up when upgrading from netcoreapp3.1 / v3 / In-process to net6.0 / v4 / In-Process but only after the function app was deployed to Azure (locally was working just fine). Similar as described with the above there is a reference to a project without dependencies.

To be explicit before starting the upgrade (netcoreapp3.1 / v3 / In-process ) the OpenApi endpoints were working fine both locally and on Azure.

Update: What also is missing from earlier comments is this only impacts the SwaggerUI page https://example.org/api/swagger/ui but the json (/api/swagger.json) and yaml (/api/swagger.yaml) routes are working.

The suggested approach to reference some NuGet package without deps isn't an option in our case as the referenced project is a private NuGet package use by multiple projects.

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

5 participants