From d826ff57cdbd6ee80879281e3e2301112feedfb7 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Fri, 22 May 2026 14:45:32 +1200 Subject: [PATCH 1/3] fix: Silence CS1701/CS1702 warnings from Add-Type on PowerShell Core 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 --- modules/Sentry/Sentry.psm1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/Sentry/Sentry.psm1 b/modules/Sentry/Sentry.psm1 index 595b59d..7ec35d8 100644 --- a/modules/Sentry/Sentry.psm1 +++ b/modules/Sentry/Sentry.psm1 @@ -5,7 +5,10 @@ $moduleInfo = Import-PowerShellDataFile (Join-Path (Split-Path -Parent $MyInvoca . "$privateDir/Get-SentryAssembliesDirectory.ps1" $sentryDllPath = (Join-Path (Get-SentryAssembliesDirectory) 'Sentry.dll') -Add-Type -TypeDefinition (Get-Content "$privateDir/SentryEventProcessor.cs" -Raw) -ReferencedAssemblies $sentryDllPath -Debug:$false +# Suppress CS1701/CS1702: Sentry.dll references System.Runtime at a version that differs from +# the one loaded by the PowerShell host (e.g. pwsh on .NET 10 vs Sentry.dll's net9.0 metadata). +# The runtime binds successfully; the warnings are noise. +Add-Type -TypeDefinition (Get-Content "$privateDir/SentryEventProcessor.cs" -Raw) -ReferencedAssemblies $sentryDllPath -CompilerOptions '/nowarn:CS1701;CS1702' -Debug:$false . "$privateDir/SentryEventProcessor.ps1" Get-ChildItem $publicDir -Filter '*.ps1' | ForEach-Object { From 7104bd60a7399b506a167b0a0e403221a0194f8b Mon Sep 17 00:00:00 2001 From: James Crosswell <728212+jamescrosswell@users.noreply.github.com> Date: Fri, 22 May 2026 14:56:21 +1200 Subject: [PATCH 2/3] fix: guard -CompilerOptions behind $PSEdition check for PS 5.1 compat -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. --- modules/Sentry/Sentry.psm1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/Sentry/Sentry.psm1 b/modules/Sentry/Sentry.psm1 index 7ec35d8..11366ef 100644 --- a/modules/Sentry/Sentry.psm1 +++ b/modules/Sentry/Sentry.psm1 @@ -5,10 +5,16 @@ $moduleInfo = Import-PowerShellDataFile (Join-Path (Split-Path -Parent $MyInvoca . "$privateDir/Get-SentryAssembliesDirectory.ps1" $sentryDllPath = (Join-Path (Get-SentryAssembliesDirectory) 'Sentry.dll') -# Suppress CS1701/CS1702: Sentry.dll references System.Runtime at a version that differs from -# the one loaded by the PowerShell host (e.g. pwsh on .NET 10 vs Sentry.dll's net9.0 metadata). -# The runtime binds successfully; the warnings are noise. -Add-Type -TypeDefinition (Get-Content "$privateDir/SentryEventProcessor.cs" -Raw) -ReferencedAssemblies $sentryDllPath -CompilerOptions '/nowarn:CS1701;CS1702' -Debug:$false +$addTypeParams = @{ + TypeDefinition = (Get-Content "$privateDir/SentryEventProcessor.cs" -Raw) + ReferencedAssemblies = $sentryDllPath + Debug = $false +} +# -CompilerOptions is PS Core only; suppress CS1701/CS1702 (harmless binding-redirect noise) when available. +if ($PSEdition -eq 'Core') { + $addTypeParams['CompilerOptions'] = '/nowarn:CS1701;CS1702' +} +Add-Type @addTypeParams . "$privateDir/SentryEventProcessor.ps1" Get-ChildItem $publicDir -Filter '*.ps1' | ForEach-Object { From 5557f842a68d3065c1c64d660919b51df7bb46b5 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Fri, 22 May 2026 15:07:56 +1200 Subject: [PATCH 3/3] Add changelog entry Co-Authored-By: Claude Opus 4.7 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 315ef10..4f1fe16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Silence CS1701/CS1702 warnings emitted by `Add-Type` when importing the module on PowerShell hosts whose runtime `System.Runtime` version differs from the one `Sentry.dll` was compiled against ([#129](https://github.com/getsentry/sentry-powershell/pull/129)) + ## 0.4.0 ### Fixes