-
Notifications
You must be signed in to change notification settings - Fork 708
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
NullReferenceException in QueryStringApiVersionReader.cs #952
Comments
The issue here isn't the value returned by the indexed Based on the stack trace, the issue appears to that the and It seems this should never happen. The code was all updated with If this is a bug, there isn't really a way for me to get it out to you. I can make the fix, but there's no way for me to publish it. Microsoft has continued to drag its feet on enabling that for me and, at this point, I've pretty much surrendered to the fact it is unlikely to ever happen. The only other option is to publish a standalone release that you'd have consume by ingesting it into your package management system like I did with 5.1. I'm not sure what the options for you to upgrade are. You didn't mention what version of .NET you're targeting. If it's >= .NET 6.0, that is not officially supported by the 5.x release. There is a strong pairing between .NET major releases. It might work, but there have been cases where things didn't always work as expected. It's been about 2 years since I've touched any of the .NET 5.0 stuff, but I'm happy to help you investigate and come up with a workable solution. |
Hey there, Yeah we're targeting 6.0 - we'll try playing around with moving the version up (I think there were namespace changes in there?) in the next few sprints. I agree it's very, very bizarre. The error itself is extremely intermittent - prior to this release we just did, we were getting this about 1/10000 requests, now since our latest release (no idea honestly looking at the diffs) it's like 1/1000. For now, we've just disabled the querystring versioning since it was only a shim anyway for testing things for our clients, but we'll try upgrading initially, see if it fixes the problem. If not, then we'll go ahead and inherit from the query string api version reader, override that value and drop a /shrug catch in there for this weird case. We're definitely not setting that value to null anywhere, and there's really no rhyme or reason that I can pick out as to why we're getting nulls there occasionally (even on the EXACT same request - IE, issuing the exact same request 1000 times now will yield a 500 sporadically). No fancy middleware or anything screwing with the request, so at this point I'm at a loss. |
Agreed. I got so hung up on trying to fix it for you 😉 ... that - yeah - you can totally extend or fork the implementation into a reader that tests and guards against This only other place I can think of where this behavior might be happening is you have some kind of work at the end of the pipeline. If you tried to get the requested API version at the end of the pipeline, it's possible the |
Did you ever discover more information or were you able to resolve the issue? |
Yeah this has led us down quite the rabbit hole - We think it's actually related to this: We think that somehow the thread safety issue of httpcontextaccessor is getting tripped because there's parallel dependency telemetry data that's getting sent up to application insights. We noted that if we killed app insights altogether, the problem went away. Still just a shot in the dark, but we've upgraded everything from system.data.sqlclient to microsoft.data.sqlclient in hopes that we could resolve this issue. We'll see what happens when this next release goes out. Crossing fingers. |
++ Sorry, extra piece of context - we have a telemetry initializer that relies on httpcontextaccessor that grabs some info to append into logs (correlation id and all that) |
Thanks for the clarification. I don't I would have ever guessed something like that. 😸 |
Yeah. You can consider this issue closed if you'd like in the interim, I'll update once we have some actually real runtime data to look at once this gets deployed to prod. |
Since this issue appears to be external, I'm going to close out per @phalpin. If there is something additional to add for future readers, feel free to do so. The issue can be reopened later if necessary. |
aspnet-api-versioning/src/AspNetCore/WebApi/src/Asp.Versioning.Http/QueryStringApiVersionReader.cs
Line 38 in d71f42d
Getting an intermittent null reference exception in one of our applications -
Swapping from QueryStringApiVersionReader to HeaderApiVersionReader alleviates the issue. Noticed in the codebase (we're currently using 5.0 - so a little behind) - in 5.0 (and in the latest, I think?) the reference to the request's querystring is not calling TryGetValue - from our stack traces it looks like that's where the null is originating.
We're ok for the moment swapping to just header version parsing - however, wanted to bubble up this issue, see if anyone else had the same problem.
Thanks!
The text was updated successfully, but these errors were encountered: