Skip to content

PrimaryResourceType is null and giving error "Expected IJsonApiRequest.PrimaryResourceType not to be null at this point." #1519

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

Closed
AnushreeSoman21 opened this issue Mar 27, 2024 · 6 comments
Labels

Comments

@AnushreeSoman21
Copy link

AnushreeSoman21 commented Mar 27, 2024

SUMMARY

I attempted to create an API using JsonAPIDotNetCore, however I was receiving an exception with the message "Expected IJsonApiRequest.PrimaryResourceType not to be null at this point" when I tried to call the GetAsync API for an entity.

DETAILS

I have developed controllers by inheriting BaseJsonapicontroller exactly like below and am attempting to call the GetAsync API. I am using Jsonapidotnetcore 5.5.1,.NET 8, and EFCore 8. This gives the error as "Expected IJsonApiRequest.PrimaryResourceType not to be null at this point."

Controller -
public class DemoController : BaseJsonApiController<Demo, long>

VERSIONS USED

  • JsonApiDotNetCore version: 5.5.1
  • ASP.NET Core version: 8
  • Entity Framework Core version: 8
  • Database provider: SQL

I've looked over one of the jsonapidotnetcore issues in your problem list and have attempted the same solutions, but nothing has worked. (PrimaryResourceType not to be null at this point #1285)

Note: I have recently updated the API from .NET 6 to .NET8 and JsonAPIDotNEtCore package from 5.1.0 to 5.5.0

@bkoelman
Copy link
Member

Hi @AnushreeSoman21, thanks for reaching out. I'm not seeing anything wrong in what you've described. Can you share a minimal repro project so I can analyse what's happening?

@AnushreeSoman21
Copy link
Author

JSONAPISample.zip

I have used your sample project only but still facing the same issue. Attached sample project here

@bkoelman
Copy link
Member

Thanks, that explains a lot!

This issue should have started with: I'm trying to hack in OpenAPI support, but can't get that to work.

You're running into the exact same problem as reported in #1285, which you already linked to. Apparently, you added builder.Services.AddControllers(); (which breaks many things by itself), so you'll see some endpoints show up in SwaggerUI. However, what you see there is completely wrong, as indicated in our FAQ. There's a good reason we've been working on OpenAPI support for a long time: it's not that simple.

If you'd like to use OpenAPI, pick the experimental version from our dev feed and install as described here. See also the documentation on using OpenAPI.

Otherwise, just removing the lines you added:

builder.Services.AddControllers();
builder.Services.AddSwaggerDocument();
builder.Services.AddEndpointsApiExplorer();

makes your repro work just fine.

@AnushreeSoman21
Copy link
Author

Hi @bkoelman,

Thank you for the response. I have tried removing below lines of code and swagger support but still it is not working for me.

builder.Services.AddControllers();
builder.Services.AddSwaggerDocument();
builder.Services.AddEndpointsApiExplorer();

and swagger support but still it is not working for me.

app.UseOpenApi();
app.UseSwaggerUI();

@bkoelman
Copy link
Member

Can you be more specific? What have you tried exactly?
If I download your project and comment out those lines, a GET request to http://localhost:5210/api/books returns the list of books.

Does the GettingStarted sample work on your machine? If not, can you try adding things from your project one-by-one until it breaks?

What you can also try is clearing caches, restart your IDE, etc.

@bkoelman bkoelman reopened this Mar 28, 2024
@bkoelman
Copy link
Member

bkoelman commented Apr 8, 2024

Closing due to inactivity. Please provide the requested information if you need this issue to be reopened.

@bkoelman bkoelman closed this as not planned Won't fix, can't repro, duplicate, stale Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants