rbeauchamp / Swashbuckle.OData

Extends Swashbuckle with OData v4 support!
Other
129 stars 96 forks source link

Error logged during debugging in Visual Studio: "'System.Web.Http.HttpResponseException' in System.Web.OData.dll" when browsing URL http://<webapiuri>/swagger #165

Closed JohanKarnell closed 4 years ago

JohanKarnell commented 6 years ago

Hi,

I have an OData Web API with Entity Framework on which I want to add swagger.

Short description of my Web API: OData Web API using Entity Framework to retrieve data from a db. The Web API has a custom DelegatingHandler executed before the controllers that I use to log the request/response to a third party application.

The issue I am facing: Visual Studio 2015 diagnostic events shows that a lot of errors are thrown and handled in System.Web.OData.dll and System.Web.Http.dll during debugging when the operations are loaded after browsing to http://localhost:port/swagger. But the operations are loaded successfully in the web browser and trying them out works as well.

Error message 1 logged in Visual Studio Diagnostics log during debugging: Exception thrown: 'System.Web.Http.HttpResponseException' in System.Web.OData.dll Error message 2 logged in Visual Studio Diagnostics log during debugging: Exception thrown: 'System.Web.Http.HttpResponseException' in System.Web.Http.dll

Followed these steps when adding swagger to my Web API:

  1. Installed Swashbuckle nuget package (5.6.0)

  2. Installed Swashbuckle.OData nuget package (3.4.0)

  3. Added this to .EnableSwagger in order to include NavigationProperties c.CustomProvider(defaultProvider => new ODataSwaggerProvider(defaultProvider, c, GlobalConfiguration.Configuration).Configure(odataConfig => { odataConfig.EnableSwaggerRequestCaching(); odataConfig.IncludeNavigationProperties(); }));

  4. Started debugging Web API in Visual Studio 2015 Update 3

  5. Web API loads successfully and then I browse to "/swagger" bild

  6. Swagger starts loading the operations but suddently a lot of exceptions with the errors mentioned earlier is shown in the diagnostics event log bild

  7. Swagger UI loads the operations successfully and then it's possible to look at all the operations and try them out bild

  8. Everything seems to work but I cannot understand why the errors are thrown

Question: Any ideas what the errors showing in the Visual Studio Diagnostic events are and why they occur?

I have not been able to get a more detailed error description than the ones described above. I understand that this is probably not an issue with Swashbuckle since I haven't been able to find anyone else with similar issues but I couldn't think of a better place to ask my Question.

ecozoic commented 6 years ago

I have the same issue.

I see 4 of these in the Debug console: Exception thrown: 'System.Web.Http.HttpResponseException' in System.Web.OData.dll

My setup is exactly like yours (OData + Swashbuckle + Swashbuckle.OData). Everything seems to work fine, but thrown exceptions don't exactly make you feel great...

It's definitely tied to Swashbuckle.OData somehow. If I remove the line setting it as the custom Swagger provider, issue goes away.