-
Notifications
You must be signed in to change notification settings - Fork 704
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
Raw Requested API Versions Causes Stack Overflow #1017
Comments
This happens because of fallback behavior at: aspnet-api-versioning/src/AspNetCore/WebApi/src/Asp.Versioning.Http/ApiVersioningFeature.cs Line 38 in f29831e
This was primarily intended to support simplifying testing, but it can surface at runtime. The This only happens if API Versioning has not been properly configured via |
Ran into this exact same thing while upgrading from 5.0.0 to 5.0.1 All our controller unit tests started failing on it. Seems to be a breaking change in a minor update. |
@jcageman There is no I reviewed the changes from With a little more context and understanding, I'd consider backporting the fix. Unless you have a very compelling reason, you should be moving to Asp.Versioning.Mvc. The older packages are in maintenance mode for servicing only and do not officially support newer versions of .NET or ASP.NET Core. The Asp.Versioning.Mvc package (and company) supports .NET 6, .NET 7, and will support .NET 8 and beyond. |
Indeed meant i think the stack overflow due to this construction in our mocking code:
After updating i also get a ArgumentNullException on the following code:
With callstack: Stack Trace:
This was all working fine with 5.0.0 |
I see. The primary issue is that the required services haven't been setup as noted above. There are several ways to make the necessary setup work. Option 1: Register the Built-In ServicesSet up a provider that registers the necessary services: var services = new ServiceCollection();
services.AddApiVersioning();
_mockHttpContext.SetupProperty(hc => hc.RequestServices, services.BuildServiceProvider()); Option 2: Build a Mocked Service ProviderIf you prefer a more stripped down provider, it's easy to set one up: var services = new Mock<IServiceProvider>();
var reader = new QueryStringApiVersionReader();
services.Setup(s => s.GetService(typeof(IApiVersionReader))).Returns(reader);
_mockHttpContext.SetupProperty(hc => hc.RequestServices, services.Object); NullReferenceExceptionI see how this happens, but I would expect this to happen in previous versions too. The following is the aspnet-api-versioning/src/Microsoft.AspNetCore.Mvc.Versioning/Versioning/ApiVersioningFeature.cs Line 34 in 435a17e
The feature tries to resolve Built-In Feature Extension MethodStarting in _mockHttpContext.SetupGet(c => c.Features).Returns(new FeatureCollection());
var feature = _mockHttpContext.Object.Features.ApiVersioningFeature(); It doesn't do anything that fancy. You can see the implementation at: aspnet-api-versioning/src/Microsoft.AspNetCore.Mvc.Versioning/HttpContextExtensions.cs Line 18 in 0612bbd
ConclusionGlad to hear you know about the updates and have a plan to transition at some point. My hands have really been tied on that and I find there are still a lot of people using the older versions and/or expecting updates. I'm thinking of marking the old packages as deprecated (which I think I can do) and hopefully that will bring awareness - if not by shock. 😛 The workarounds here are pretty straight forward, but if you really need/want a fix, I can queue something up. As an army of one, it is a lot to maintain multiple versions. Now that .NET has a clear LTS and STS strategy, I already have to content with two live branches. I try not to patch the older versions unless I really have to. A lot has changed between |
Thanks for the very elaborate response! Agree with it completely! For now we can workaround it with your provided answer and will ensure we also plan the upgrade towards the new nuget. |
Is there an existing issue for this?
Describe the bug
When calling the
HttpContext.ApiVersioningFeature()
extension method and accessingIApiVerisoningFeature.RawRequestedApiVersions
, it is possible for infinite recursion to occur which causesStackOverflowException
.Expected Behavior
No exception should occur.
Steps To Reproduce
Exceptions (if any)
StackOverflowException
.NET Version
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: