Skip to content

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

Merged
jamescrosswell merged 4 commits into
mainfrom
fix/cs1701-warnings
May 25, 2026
Merged

fix: Silence CS1701/CS1702 warnings from Add-Type on PowerShell Core#129
jamescrosswell merged 4 commits into
mainfrom
fix/cs1701-warnings

Conversation

@jamescrosswell
Copy link
Copy Markdown
Collaborator

@jamescrosswell jamescrosswell commented May 22, 2026

Summary

The call to Add-Type in Sentry.psm1 emits CS1701 warnings on PowerShell Core if the host's runtime System.Runtime version doesn't match the one Sentry.dll was compiled against (e.g. pwsh 7.6 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 #132.

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
@jamescrosswell jamescrosswell merged commit 78b6a03 into main May 25, 2026
9 checks passed
@jamescrosswell jamescrosswell deleted the fix/cs1701-warnings branch May 25, 2026 08:00
@github-actions
Copy link
Copy Markdown
Contributor

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Fixes

- Silence CS1701/CS1702 warnings from Add-Type on PowerShell Core ([#129](https://github.com/getsentry/sentry-powershell/pull/129))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 707daed

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.

Suppress CS1701/CS1702 binding-redirect warnings from Add-Type on PowerShell Core

2 participants