You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes three bugs across route/query parameter binding, IApiResponse.ContentHeaders lifetime, and response body buffering error handling, fixes the .NET 11 RC2 Native AOT smoke publish, and updates non-pinned NuGet dependencies to their latest versions.
Disambiguates route and query parameters that share the same case-insensitive URL name so non-[Query] parameters and exact-case matches bind the route placeholder while sibling parameters remain query parameters in both the source generator and reflection request builders.
Preserves IApiResponse.ContentHeaders.ContentLength across HttpContent buffering and disposal so reading ContentLength after response disposal returns null instead of throwing ObjectDisposedException when the response omitted an explicit Content-Length header.
Surfaces the original transport exception when response body buffering fails mid-stream and subsequent content deserialization fails because the underlying response stream was already consumed.
Sets PublishDocumentationFile=false when PublishAot=true so .NET 11 RC2's UseOptimizedPublish (which skips CopyFilesToOutputDirectory) does not fail looking for @(FinalDocFile) in bin/, and updates non-pinned NuGet packages across src/.
Why
When an endpoint declared both a route parameter and a case-differing query parameter (such as [Get("/test/{id}")] with string id and [Query] string ID), case-insensitive route matching bound both parameters to {id} in the source generator and overwrote the route parameter in the reflection builder. Closes[Bug]: Issue with case differing path/query parameters #2356.
Accessing IApiResponse.ContentHeaders.ContentLength on a disposed response whose HttpContent had no explicit Content-Length header caused HttpContentHeaders.ContentLength to lazily invoke GetComputedOrBufferLength() on the disposed HttpContent and throw ObjectDisposedException. Closes[Bug]: IApiResponse.ContentHeaders.ContentLength throws ObjectDisposedException #2357.
When LoadIntoBufferAsync failed mid-stream on a single-read network stream (HttpIOException / IOException), TryBufferContentAsync swallowed the transport exception and allowed FromHttpContentAsync to run against the already-consumed stream, reporting a misleading InvalidOperationException("The stream was already consumed. It cannot be read again.") inside ApiException. Closes[Bug]: Transport failure while buffering the response body is swallowed and reported as a deserialization error #2359.
Breaking changes
None.
How this was verified
Added unit and live request-building tests covering case-differing route/query parameter combinations (including source-generator and reflection parity), ContentHeaders.ContentLength access after response disposal, and mid-stream response buffering failures for both direct and ApiResponse<T> return shapes; verified Native AOT publishing for Refit.NativeAotSmoke and NativeClient.
Compare Parser.Request.Parameters.cs and RestMethodInfoInternal.ParameterBinding.cs for the route candidate ranking logic ([Bug]: Issue with case differing path/query parameters #2356); in both paths, the sibling disambiguation only runs when multiple parameters share a case-insensitive URL name.
Deliberately pinned dependencies (Microsoft.CodeAnalysis.* / MsCACSharpVersion and legacy System.*4.3.x packages) were left untouched.
- Disambiguate route and query parameters when sibling parameters share the same case-insensitive URL name (#2356)
- Preserve uncomputed ContentHeaders.ContentLength across HttpContent buffering and disposal (#2357)
- Rethrow original transport exception when response buffering fails on a single-read stream and deserialization subsequently throws (#2359)
Fixes#2356Fixes#2357Fixes#2359
glennawatson
changed the title
fix: resolve open issues #2356, #2357, and #2359
fix: disambiguate case-differing parameters, preserve ContentLength header, and surface buffering exceptions
Oct 16, 2026
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (970bf3e) to head (0b6c8e0). ⚠️ Report is 1 commits behind head on main.
…lish
- Disable PublishDocumentationFile when PublishAot is true so .NET 11 RC2 UseOptimizedPublish does not fail copying @(FinalDocFile) from bin/
- Update non-pinned NuGet packages to latest versions and await NUnit 5.0.0 Assert.ThrowsAsync in documentation examples
Addresses route/query binding, response-header lifetime, and buffering-error reporting in Refit. Also updates dependencies and Native AOT publishing configuration.
Changes:
Adds case-sensitive route-candidate ranking and generated/reflection parity tests.
Preserves content-length headers and original buffering exceptions, with regression coverage.
Updates NuGet dependencies, NUnit examples, and AOT documentation publishing.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
The non-query bonus can override reservation for another placeholder in both this method and RestMethodInfoInternal.GetRouteCandidateRank. For /accounts/{id}/positions/{ID} with (int id, [Query] int ID) and values (10, 20), id scores 3 for {ID} while the exact match scores 2. Both placeholders therefore use id, producing /accounts/10/positions/10?ID=20 instead of /accounts/10/positions/20. Swapping which parameter has [Query] causes the opposite misbinding. In both implementations, return claimedByOtherPlaceholderRank before applying the non-query bonus when caseRank has that value. Add live parity tests covering both mixed-annotation arrangements; the existing both-bare-query and formatted-query cases do not cover this.
For /accounts/{Id}/positions/{ID} with (int id, [Query, AliasAs("ID")] int secondId), id scores 4 for both placeholders because it has no exact-case placeholder. It therefore beats secondId's exact-match score of 2 for {ID}. Arguments (10, 20) produce /accounts/10/positions/10?ID=20 instead of /accounts/10/positions/20.
The same ranking exists in src/Refit.Reflection/RestMethodInfoInternal.ParameterBinding.cs:264-266. Resolve assignments across the sibling group so the fallback for {Id} does not also take the sibling's exact {ID} binding. Update both builders and add this mixed-attribute case to the live parity tests; the existing mixed-attribute tests use exact {id}.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three bugs across route/query parameter binding,
IApiResponse.ContentHeaderslifetime, and response body buffering error handling, fixes the.NET 11 RC2Native AOT smoke publish, and updates non-pinned NuGet dependencies to their latest versions.[Query]parameters and exact-case matches bind the route placeholder while sibling parameters remain query parameters in both the source generator and reflection request builders.IApiResponse.ContentHeaders.ContentLengthacrossHttpContentbuffering and disposal so readingContentLengthafter response disposal returnsnullinstead of throwingObjectDisposedExceptionwhen the response omitted an explicitContent-Lengthheader.PublishDocumentationFile=falsewhenPublishAot=trueso.NET 11 RC2'sUseOptimizedPublish(which skipsCopyFilesToOutputDirectory) does not fail looking for@(FinalDocFile)inbin/, and updates non-pinned NuGet packages acrosssrc/.Why
[Get("/test/{id}")]withstring idand[Query] string ID), case-insensitive route matching bound both parameters to{id}in the source generator and overwrote the route parameter in the reflection builder. Closes [Bug]: Issue with case differing path/query parameters #2356.IApiResponse.ContentHeaders.ContentLengthon a disposed response whoseHttpContenthad no explicitContent-Lengthheader causedHttpContentHeaders.ContentLengthto lazily invokeGetComputedOrBufferLength()on the disposedHttpContentand throwObjectDisposedException. Closes [Bug]: IApiResponse.ContentHeaders.ContentLength throws ObjectDisposedException #2357.LoadIntoBufferAsyncfailed mid-stream on a single-read network stream (HttpIOException/IOException),TryBufferContentAsyncswallowed the transport exception and allowedFromHttpContentAsyncto run against the already-consumed stream, reporting a misleadingInvalidOperationException("The stream was already consumed. It cannot be read again.")insideApiException. Closes [Bug]: Transport failure while buffering the response body is swallowed and reported as a deserialization error #2359.Breaking changes
None.
How this was verified
Added unit and live request-building tests covering case-differing route/query parameter combinations (including source-generator and reflection parity),
ContentHeaders.ContentLengthaccess after response disposal, and mid-stream response buffering failures for both direct andApiResponse<T>return shapes; verified Native AOT publishing forRefit.NativeAotSmokeandNativeClient.Notes for the reviewer
RequestExecutionHelpers.csfor both thePreserveContentLengthHeaderhelper ([Bug]: IApiResponse.ContentHeaders.ContentLength throws ObjectDisposedException #2357) and theTryBufferContentAsync/DeserializeSerializedContentAsyncexception propagation ([Bug]: Transport failure while buffering the response body is swallowed and reported as a deserialization error #2359). Note thatTryBufferContentAsyncintentionally still allows deserialization to proceed ifLoadIntoBufferAsyncthrows on a customHttpContentwhose stream remains readable, only rethrowing the buffering exception when the serializer also fails.Parser.Request.Parameters.csandRestMethodInfoInternal.ParameterBinding.csfor the route candidate ranking logic ([Bug]: Issue with case differing path/query parameters #2356); in both paths, the sibling disambiguation only runs when multiple parameters share a case-insensitive URL name.Microsoft.CodeAnalysis.*/MsCACSharpVersionand legacySystem.*4.3.xpackages) were left untouched.Checklist