Registry sample: retarget net10.0, MSTest 4.3.3, and honest CI for the Windows-only tests - #2166
Open
vladimir-pecanac-main wants to merge 1 commit into
Open
Conversation
…tests, CI Live filter
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
ReadWriteWindowsRegistryInCSharpsample that backs Read and Write Windows Registry in C#.Retarget
net7.0->net10.0. Deliberately plainnet10.0, notnet10.0-windows: the twoCA1416warnings the article prints and explains only exist because the TFM is platform-neutral, andnet10.0-windowswould also break the Linux CI build.Microsoft.NET.Test.Sdk17.6.0 -> 18.9.0,MSTest.TestAdapter/MSTest.TestFramework2.2.10 -> 4.3.3,coverlet.collector3.2.0 -> 10.0.1.Sample fixes
CreateSubKey(string)returns a non-nullableRegistryKey, soOpenSubKey(name, true) ?? CreateSubKey(name)is non-nullable too, and everysubKey?.after it taught the reader the opposite of the truth.Array.Empty<string>()->[].Path.Combine()to build strings that are not paths: one builds a registry path, the other an NT account name. Both happened to work only becausePath.Combinejoins with\on Windows. Replaced with explicit interpolation.OpenRemoteBaseKey(): the returned key was assigned to an unused variable and never disposed, andcatch { }swallowed everything. Nowusingon the returned key, and the catch is narrowed toArgumentExceptionandIOException(an unreachable machine and a stopped Remote Registry service both surface asArgumentExceptionviaArg_RegKeyNoRemoteConnect).Honest CI on a Windows-only sample
Every test here writes and deletes a subkey under
HKEY_CURRENT_USERon the machine that runs it. They all used to open withif (!OperatingSystem.IsWindows()) return;, so the Linux runner reported 10 passed having asserted nothing.Live.dotnet test ... --filter "FullyQualifiedName!~Live"), identical line, merge-safe duplicate. A PR runs the workflow from its own branch, so without it here the renamed tests would run on the Linux runner and fail.Verification
dotnet build -c Releaseon SDK 10.0.302: 0 errors. 2CA1416warnings in the app project (the two the article shows), plus 4CA1416and 2MSTEST0017in the test project from the removed guards and the MSTest 4.x analyzers.dotnet test -c Release --no-build --filter "FullyQualifiedName!~Live": exit 0, no test matched, which is the honest result.Livetests were not run in prep: they write to the real registry.