Build a query string: retarget net10.0, safe UriBuilder helper, CS8620 fix - #2170
Open
vladimir-pecanac-main wants to merge 1 commit into
Open
Build a query string: retarget net10.0, safe UriBuilder helper, CS8620 fix#2170vladimir-pecanac-main wants to merge 1 commit into
vladimir-pecanac-main wants to merge 1 commit into
Conversation
…0 fix - net7.0 -> net10.0 across BuildQueryString, BuildQueryStringTests and BooksAPI - Package moves: Microsoft.Extensions.DependencyInjection 10.0.11, Microsoft.NET.Test.Sdk 18.9.0, MSTest.TestAdapter/TestFramework 4.3.3, Moq 4.20.72, coverlet.collector 10.0.1, Swashbuckle.AspNetCore 10.2.3 - Add BuildUrlWithQueryStringUsingUriBuilderSafely: UriBuilder composed with QueryString.Create, plus a round-trip test over 'Tom & Jerry' and 'C#' - Fix CS8620: declare the caller dictionaries as Dictionary<string, string?> where the helper takes nullable values (BooksApiService and the matching tests) - Program.cs: top-level statements
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Updates the
dotnet-querystrings/BuildQueryStringsample for the republish of How to Build a Query String for a URL in C#.Retarget
net7.0->net10.0on all three projects (BuildQueryString,BuildQueryStringTests,BooksAPI). Package versions taken from the NuGet flat-container index on 2026-08-30, not from memory:The MSTest 2.x -> 4.x jump needed no source changes: the classic
Assert.AreEqual/TestClass/TestMethodAPI compiles as-is and no MSTEST analyzer diagnostic fires in this folder.Safe
UriBuildercomposition (new helper + test)The article's central claim about
UriBuilderwas wrong: it escapes characters that are illegal anywhere in a URI, but it does not escape the query delimiters&,=and#inside a value. Assigningauthor=Tom & JerrytoQueryyields?author=Tom%20&%20Jerry, which a receiver parses as two parameters, the second namedJerry.BuildUrlWithQueryStringUsingUriBuilderSafelyis the one-line composition that does encode: build the query withQueryString.Createand hand the finished string toUriBuilder. The new test asserts the full round trip overTom & JerryandC#:parsed back to
author=Tom & Jerryandtag=C#.CS8620
BuildUrlWithQueryStringUsingAddQueryStringMethodandBuildUrlWithQueryStringUsingCreateMethodtakeDictionary<string, string?>, and every caller declaredDictionary<string, string>, which warns:Fixed at all four call sites (two in
BooksApiService, two inQueryStringHelperUnitTests). The build is now warning-clean apart from NU1510 on the DI package, which the article tells the reader to install explicitly.Idiom
BuildQueryString/Program.cslifted to top-level statements.BooksAPI/Program.cswas read and already uses minimalWebApplicationhosting with noStartup.cs, so it is untouched.Build and tests
13 pre-existing tests plus the one added. Every comparison-table cell in the article was re-produced by running the retargeted solution itself on .NET 10.0.10, not by reading reference pages.