Skip to content

ApiExplorer ApiDescription error: The invoked member is not supported before the type is created. #463

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
dmore234 opened this issue Feb 23, 2019 · 14 comments

Comments

@dmore234
Copy link

Using WebApi and oData v4. Getting exception in MultipleVersion block for EF models having navigation property. Do I have add IncludeNavigationPropery in Swagger Config file or exclude controllers having navigation property? Please advise!

The invoked member is not supported before the type is created.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: The invoked member is not supported before the type is created.

foreach (var group in apiExplorer.ApiDescriptions)....................Line 152:

@commonsensesoftware
Copy link
Collaborator

Which version of the libraries are you using? Are you using the current versions? There was an issue related to this area that has since been fixed, but there still might be a missing edge case.

Do you have a simple repro or configuration you can share. It's difficult to setup the conditions you're seeing otherwise. Thanks.

@dmore234
Copy link
Author

Swashbuckle oData 3.5.0. Rest latest version.

@dmore234
Copy link
Author

I have multiple oData controllers, is there a way to hide/not display certain controllers in Swagger UI?

I tried class level attribute [ApiExplorerSettings(IgnoreApi=true)] but it not working.

Thanks for your help!

@commonsensesoftware
Copy link
Collaborator

Oh … I think I see. Are you using the Swashbuckle.OData? If so, that's the culprit. It changes things that break API versioning. Fear not though. There's a solution and you don't need that package at all.

I strong recommend you have a deep look at the Web API OData Swagger sample project. It will show you all the packages and setup you need to get OData and Swagger working together.

API Versioning provides an extension to the API Explorer API. One of its possible uses for Swagger generation. As a result, you don't need a special variant of Swashbuckle or other Swagger generators like NSwag that use this information. You need API Versioning and plain 'ol Swashbuckle.

In your case, you packages should include:

  • API Versioning for OData on Web API
  • API Versioning API Explorer for OData on Web API
  • Swashbuckle

Again - the working example will demonstrate everything work end-to-end. Give that a whirl and let me know if you have more questions.

I may need to put something on the wiki as the incompatibility with Swashbuckle.OData has come up a few times.

@dmore234
Copy link
Author

In mentioned sample project ( .../aspnet-api-versioning-master\samples\webapi\SwaggerODataWebApiSample\Models) model Order & Person does NOT have Navigation Property.

ApiVersioning is working w/o Navigation property. I am getting error w NP.

@commonsensesoftware
Copy link
Collaborator

Navigation properties should be supported. I'll investigate further. If you have a repro or an example to share that really helps speed things up so that I can run through your exact scenario.

@dmore234
Copy link
Author

dmore234 commented Feb 26, 2019 via email

@commonsensesoftware
Copy link
Collaborator

Great, that's easier to start from; however, that the sample doesn't have any navigation properties. So what did you add or change?

@dmore234
Copy link
Author

dmore234 commented Feb 26, 2019 via email

@commonsensesoftware
Copy link
Collaborator

I'm not sure how old your sync of the repo is. I've been unable to reproduce the specific error you're describing. I added a Line Items navigation property to the Orders entity set and things worked as expected. I even varied the model between API versions, which would would trigger model substitution. Are you sure you have the most recent updates in the repo? There was a problem that has since been fixed for a while now.

As an aside, I am noticing an issue with navigation properties that are defined by convention. I'm not sure if it's a bug yet or just my misconfiguration. Personally, I prefer the attribute route approach, but both methods are supposed to work. I'll continue investigating.

@dmore234
Copy link
Author

dmore234 commented Mar 6, 2019

Can you please share the sample code where odata controller api versioning is working with navigation property entity?

@commonsensesoftware
Copy link
Collaborator

It's incomplete, but I pushed my working branch for you to look at. This updated example for Web API adds navigation properties using attribute and convention-based routing. Both routing methods resolve correctly, but the Swagger documentation isn't showing up for convention-based navigation properties. This is probably a bug in the API Explorer, but I'm still investigating.

Hopefully, this will be useful to you.

@commonsensesoftware
Copy link
Collaborator

Apologies for the long delay. Finally back to digging into this more. There is definitely a bug with navigation properties by convention; they simply are not generated. I have a basic fix for that; however, there may be additional issues with generating other types of complex navigation properties by convention such as for links (e.g. $ref).

Against what I'd like, I'm inclined to get the basic functionality out and revisit the more complex scenarios later in a separate issue. I believe the main issues stem from convention-based routes since attribute-based routes explicitly say what the template is supposed to be. Generating the correct route templates purely from reflecting the code is non-trivial. I do believe covering all of the OData conventions is ultimately possible, but the value proposition of waiting until I can iron out all possibilities seems low when the most common scenarios can be address now.

There's quite a few issues under investigation right now. I plan on addressing as many as I can before the next release to avoid churn. Thanks for you patience.

@commonsensesoftware
Copy link
Collaborator

This issue will be resolved after the next package push. Supporting all conventions will be addressed in a future iteration that is now tracked by #494. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants