Repository navigation
Fix CA1416 build failure in FileLoggerTests - #9844
Conversation
Annotate the RunLongRunning overrides in the RecordingTask and
NeverCompletingTask test doubles with [UnsupportedOSPlatform("browser")]
to match the ITask interface member. Without it, their call sites into
SystemTask.RunLongRunning were reachable on all platforms and triggered
CA1416 (treated as error) on net8.0/net9.0, failing the build on all legs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 321a8057-828d-43c4-ae07-203293449e0a
There was a problem hiding this comment.
Pull request overview
This PR fixes a CA1416 analyzer error (treated as build-breaking) in Microsoft.Testing.Platform.UnitTests by aligning the platform support annotations on ITask.RunLongRunning test-double implementations with the underlying API they delegate to.
Changes:
- Added
[UnsupportedOSPlatform("browser")]toRecordingTask.RunLongRunning. - Added
[UnsupportedOSPlatform("browser")]toNeverCompletingTask.RunLongRunning.
Show a summary per file
| File | Description |
|---|---|
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/FileLoggerTests.cs |
Adds browser platform annotations to ITask test doubles’ RunLongRunning methods to prevent CA1416 at the delegate call sites. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Low
🧪 Test quality grade — PR #9844No new or modified test methods were identified in the changed regions of this PR. The only changed test file ( Re-run with
|
There was a problem hiding this comment.
Expert Review — PR #9844: Fix CA1416 build failure in FileLoggerTests
Summary
Clean, minimal fix. No issues found.
Correctness ✅
The [UnsupportedOSPlatform("browser")] annotation is correctly applied to both RecordingTask.RunLongRunning and NeverCompletingTask.RunLongRunning to match the ITask interface member and SystemTask implementation. This resolves the CA1416 diagnostic.
Consistency ✅
The pattern matches existing usage across the test project (IPCTests, TestHostBuilderTests, ServerTests, DotnetTestDataConsumerTests, etc.) — all use [UnsupportedOSPlatform("browser")] on method overrides that delegate to browser-unsupported APIs.
Scope ✅
Surgical two-line change, no unrelated modifications.
Design note
The PR description correctly explains why only "browser" is used (not "wasi") — adding "wasi" would trigger CA1418 on the net462 target. This is consistent with the rest of the codebase.
Verdict: Looks good. No changes requested.
Problem
The CI build fails on all legs (Linux/macOS/Windows, Debug/Release) — as seen on the darc dependency PR #9839, but the root cause is on
main. The failing step is the mainBuildtask, which errors with:(CA1416 is treated as an error, which is why the build fails and no test results are produced — the subsequent "Publish Test Results" / "Copy binlogs" failures are just downstream symptoms.)
Root cause
The
ITask.RunLongRunninginterface member is annotated[UnsupportedOSPlatform("browser")], and so is theSystemTaskimplementation. The twoITasktest doubles inFileLoggerTests—RecordingTaskandNeverCompletingTask— implementRunLongRunningwithout that annotation and delegate to a realSystemTask. Their call sites into_inner.RunLongRunning(...)are therefore "reachable on all platforms" while calling a browser-unsupported API, tripping CA1416 onnet8.0/net9.0.Fix
Annotate both test-double
RunLongRunningoverrides with[UnsupportedOSPlatform("browser")]to match the interface member, matching the convention already used across this test project (e.g.IPCTests,TestHostBuilderTests). Onlybrowseris used (notwasi) to avoid CA1418 on the Windows-onlynet462target wherewasiis not a known platform name.Verification
Built
Microsoft.Testing.Platform.UnitTestsacross all TFMs (net8.0,net9.0,net462) locally: 0 warnings, 0 errors.