-
Notifications
You must be signed in to change notification settings - Fork 709
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
Comments
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. |
Swashbuckle oData 3.5.0. Rest latest version. |
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! |
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:
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. |
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. |
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. |
I used the sample code from sample you mentioned in recent past
( .../aspnet-api-versioning-master\samples\webapi\SwaggerODataWebApiSample\Models) model Order & Person
In this sample project can you add NP in Order / Person and see if multiple versioning is working or not.
Steps are:
1) Use models with NP
2) Add [Apiversion("1.0")] and 2.0 in two controllers
3) Use c.MultipleVersion code in Startup.cs ....v{apiversion}
Expectation is there should be 2 v1 & v2 in dropdown. All odata query should work like $select, $top $ expand....
Hope this will help!
Thanks!
Dilip More
Thanks for our help!
Dilip More
Sent from Outlook<http://aka.ms/weboutlook>
…________________________________
From: Chris Martinez <notifications@github.com>
Sent: Tuesday, February 26, 2019 11:20 AM
To: Microsoft/aspnet-api-versioning
Cc: dmore234; Author
Subject: Re: [Microsoft/aspnet-api-versioning] ApiExplorer ApiDescription error: The invoked member is not supported before the type is created. (#463)
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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#463 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/Atrn1I_RbKXFJSYrC0aYl1cdGTAk1QY6ks5vRV7JgaJpZM4bNu4D>.
|
Great, that's easier to start from; however, that the sample doesn't have any navigation properties. So what did you add or change? |
In our code ( model ) we had a NP in few models as this code is used for oData query. I just added the c.Multipleversion code.
in our project code
Sent from Outlook<http://aka.ms/weboutlook>
…________________________________
From: Chris Martinez <notifications@github.com>
Sent: Tuesday, February 26, 2019 11:47 AM
To: Microsoft/aspnet-api-versioning
Cc: dmore234; Author
Subject: Re: [Microsoft/aspnet-api-versioning] ApiExplorer ApiDescription error: The invoked member is not supported before the type is created. (#463)
Great, that's easier to start from; however, that the sample doesn't have any navigation properties. So what did you add or change?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#463 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/Atrn1PEKEUemRXG60Qg11yIU7Fw9WpHMks5vRWUYgaJpZM4bNu4D>.
|
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. |
Can you please share the sample code where odata controller api versioning is working with navigation property entity? |
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. |
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. 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. |
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. |
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:
The text was updated successfully, but these errors were encountered: