From bca5493608b20888a6b196206ef62f9c96a59181 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 20 Oct 2025 20:13:41 +0200 Subject: [PATCH 1/4] fix: Add PowerShell 7.5.2+ compatibility for SynchronousTransport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PowerShell 7.5.2 introduced changes to property assignment in class constructors when inheriting from .NET base classes. This caused SynchronousTransport to fail with "The property 'ProcessEnvelope' cannot be found on this object" errors. Changes: - Replace individual [System.Reflection.MethodInfo] properties with a single hashtable to store reflection methods - Add null checks for all reflection-based lookups to provide clear error messages if Sentry SDK internals change - Remove 'hidden' keyword from logger property (no longer needed) This fix is backward compatible and works with both PowerShell 7.5.2+ and earlier versions. Fixes #91 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Sentry/private/SynchronousTransport.ps1 | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/modules/Sentry/private/SynchronousTransport.ps1 b/modules/Sentry/private/SynchronousTransport.ps1 index e722745..6dd027d 100644 --- a/modules/Sentry/private/SynchronousTransport.ps1 +++ b/modules/Sentry/private/SynchronousTransport.ps1 @@ -2,10 +2,11 @@ # then translate the response back to a .NET HttpResponseMessage. # There are limited options to perform synchronous operations in Windows PowerShell 5.1 on .NET 4.6, so this is a workaround. class SynchronousTransport : Sentry.Http.HttpTransportBase, Sentry.Extensibility.ITransport { - hidden [Sentry.Extensibility.IDiagnosticLogger] $logger - hidden [System.Reflection.MethodInfo] $ProcessEnvelope - hidden [System.Reflection.MethodInfo] $CreateRequest - hidden [System.Reflection.MethodInfo] $SerializeToStream + [Sentry.Extensibility.IDiagnosticLogger] $logger + # PowerShell 7.5.2+ changed how property assignment works in constructors when inheriting from .NET classes. + # Using a hashtable instead of individual [System.Reflection.MethodInfo] properties works around this issue. + # See: https://github.com/PowerShell/PowerShell/releases/tag/v7.5.2 + [hashtable] $reflectionMethods = @{} SynchronousTransport([Sentry.SentryOptions] $options) : base($options) { $this.logger = $options.DiagnosticLogger @@ -15,16 +16,31 @@ class SynchronousTransport : Sentry.Http.HttpTransportBase, Sentry.Extensibility # These are internal methods, so we need to use reflection to access them. $instanceMethod = [System.Reflection.BindingFlags]::Instance + [System.Reflection.BindingFlags]::NonPublic + [System.Reflection.BindingFlags]::Public; - $this.ProcessEnvelope = [Sentry.Http.HttpTransportBase].GetMethod('ProcessEnvelope', $instanceMethod) - $this.CreateRequest = [Sentry.Http.HttpTransportBase].GetMethod('CreateRequest', $instanceMethod) + $this.reflectionMethods['ProcessEnvelope'] = [Sentry.Http.HttpTransportBase].GetMethod('ProcessEnvelope', $instanceMethod) + if ($null -eq $this.reflectionMethods['ProcessEnvelope']) { + throw "Failed to find ProcessEnvelope method on Sentry.Http.HttpTransportBase" + } + + $this.reflectionMethods['CreateRequest'] = [Sentry.Http.HttpTransportBase].GetMethod('CreateRequest', $instanceMethod) + if ($null -eq $this.reflectionMethods['CreateRequest']) { + throw "Failed to find CreateRequest method on Sentry.Http.HttpTransportBase" + } + $EnvelopeHttpContentType = [Sentry.SentrySdk].Assembly.GetType('Sentry.Internal.Http.EnvelopeHttpContent') - $this.SerializeToStream = $EnvelopeHttpContentType.GetMethod('SerializeToStream', $instanceMethod) + if ($null -eq $EnvelopeHttpContentType) { + throw "Failed to find Sentry.Internal.Http.EnvelopeHttpContent type" + } + + $this.reflectionMethods['SerializeToStream'] = $EnvelopeHttpContentType.GetMethod('SerializeToStream', $instanceMethod) + if ($null -eq $this.reflectionMethods['SerializeToStream']) { + throw "Failed to find SerializeToStream method on EnvelopeHttpContent" + } } [System.Threading.Tasks.Task] SendEnvelopeAsync([Sentry.Protocol.Envelopes.Envelope] $envelope, [System.Threading.CancellationToken]$cancellationToken = [System.Threading.CancellationToken]::None) { - $processedEnvelope = $this.ProcessEnvelope.Invoke($this, @($envelope)) + $processedEnvelope = $this.reflectionMethods['ProcessEnvelope'].Invoke($this, @($envelope)) if ($processedEnvelope.Items.count -gt 0) { - $request = $this.CreateRequest.Invoke($this, @($processedEnvelope)) + $request = $this.reflectionMethods['CreateRequest'].Invoke($this, @($processedEnvelope)) $headers = @{} foreach ($header in $request.Headers) { @@ -34,7 +50,7 @@ class SynchronousTransport : Sentry.Http.HttpTransportBase, Sentry.Extensibility } $memoryStream = [System.IO.MemoryStream]::new() - $this.SerializeToStream.Invoke($request.Content, @($memoryStream, $null, $cancellationToken)) + $this.reflectionMethods['SerializeToStream'].Invoke($request.Content, @($memoryStream, $null, $cancellationToken)) $memoryStream.Position = 0 if ($null -ne $this.logger) { From 9bd8f7030a13770b0320cd7c25104941aa896036 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:19:00 +0200 Subject: [PATCH 2/4] chore: update tests/test-pwsh-7.5.props to v7.5.3 (#98) Co-authored-by: GitHub --- tests/test-pwsh-7.5.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-pwsh-7.5.props b/tests/test-pwsh-7.5.props index c0d281b..f3f218d 100644 --- a/tests/test-pwsh-7.5.props +++ b/tests/test-pwsh-7.5.props @@ -1,2 +1,2 @@ -version = v7.5.0 +version = v7.5.3 repo = https://github.com/PowerShell/PowerShell/ From 8192aa4552c63b168e7fd7a30f855ca2bf7e5a41 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:20:30 +0200 Subject: [PATCH 3/4] chore: update tests/test-pwsh-latest.props to v7.5.3 (#96) Co-authored-by: GitHub --- tests/test-pwsh-latest.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-pwsh-latest.props b/tests/test-pwsh-latest.props index c0d281b..f3f218d 100644 --- a/tests/test-pwsh-latest.props +++ b/tests/test-pwsh-latest.props @@ -1,2 +1,2 @@ -version = v7.5.0 +version = v7.5.3 repo = https://github.com/PowerShell/PowerShell/ From 3ee45ddd9926401290d205d3baa3c42121d1b491 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 20 Oct 2025 20:32:22 +0200 Subject: [PATCH 4/4] chore: update CHANGELOG.md for PowerShell 7.5.2+ fix --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6561e0..6d0771a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Fix PowerShell 7.5.2+ compatibility for SynchronousTransport ([#105](https://github.com/getsentry/sentry-powershell/pull/105)) + ### Dependencies - Bump Dotnet SDK from v5.4.0 to v5.16.1 ([#83](https://github.com/getsentry/sentry-powershell/pull/83), [#89](https://github.com/getsentry/sentry-powershell/pull/89))