Skip to content

fix: Silence CS1701/CS1702 warnings from Add-Type on PowerShell Core#129

Open
jamescrosswell wants to merge 3 commits into
mainfrom
fix/cs1701-warnings
Open

fix: Silence CS1701/CS1702 warnings from Add-Type on PowerShell Core#129
jamescrosswell wants to merge 3 commits into
mainfrom
fix/cs1701-warnings

Conversation

@jamescrosswell
Copy link
Copy Markdown
Collaborator

@jamescrosswell jamescrosswell commented May 22, 2026

Summary

The module's Add-Type call in Sentry.psm1 was emitting five CS1701 warnings on PowerShell Core whenever the host's runtime System.Runtime version didn't match the one Sentry.dll was compiled against (e.g. pwsh on .NET 10 loading the net9.0 build of Sentry). The binding succeeds and the module works, but the warnings are noisy and look alarming.

Pass /nowarn:CS1701;CS1702 via -CompilerOptions so the harmless binding-redirect warnings are suppressed while real compile errors still surface.

Verified locally on pwsh 7.6.1: 5 CS1701 warnings before the change, 0 after, and Invoke-Pester tests/ still passes (65 passed, 3 skipped).

Note

-CompilerOptions doesn't exist on Add-Type in Windows PowerShell 5.1 (Desktop edition) — it's PowerShell Core only so we only add CompilerOptions when $PSEdition -eq 'Core'

Closes #123

jamescrosswell and others added 3 commits May 22, 2026 14:45
Roslyn was emitting five CS1701 warnings when importing the module on
PowerShell hosts whose runtime System.Runtime version differs from the
one Sentry.dll was compiled against (e.g. pwsh on .NET 10 vs Sentry.dll
for net9.0). The binding succeeds and the module works fine, but the
warnings are noisy and look alarming to first-time users.

Pass /nowarn:CS1701;CS1702 via -CompilerOptions on the Add-Type call so
the harmless binding-redirect warnings are suppressed while real compile
errors still surface.

Closes #123

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
-CompilerOptions is not available on Add-Type in Windows PowerShell 5.1
(Desktop edition). Gate it on $PSEdition -eq 'Core' so the module still
loads under powershell.exe while PS Core continues to suppress the
CS1701/CS1702 binding-redirect noise.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@jamescrosswell jamescrosswell marked this pull request as ready for review May 22, 2026 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Silence Add-Type CS1701 System.Runtime version warnings

2 participants