From 1a771df3f407e1ea66556ebbf06a41bcc1d58d12 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Sat, 19 Sep 2026 00:38:22 +0900 Subject: [PATCH 1/2] fix: Preserve Mono config types stripped by the linker --- .github/workflows/test-build-windows-mono.yml | 11 ++--- .../MonoLinkerProcessor.cs | 42 +++++++++++++++++++ test/IntegrationTest/CommonTestCases.ps1 | 4 ++ 3 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/Sentry.Unity.Editor/MonoLinkerProcessor.cs diff --git a/.github/workflows/test-build-windows-mono.yml b/.github/workflows/test-build-windows-mono.yml index 66b7e29ee..2fad1218c 100644 --- a/.github/workflows/test-build-windows-mono.yml +++ b/.github/workflows/test-build-windows-mono.yml @@ -77,14 +77,9 @@ jobs: - name: Add Sentry to the project run: ./test/Scripts.Integration.Test/add-sentry.ps1 -UnityPath "$env:UNITY_PATH" -PackagePath "test-package-release" - - name: Download DependencyConflict package - uses: ./.github/actions/wait-for-artifact - with: - name: dependency-conflict-package - path: dependency-conflict-package - - - name: Add DependencyConflict to the project - run: ./test/Scripts.Integration.Test/add-dependency-conflict.ps1 -PackagePath "dependency-conflict-package" + # The package's unaliased System.Text.Json throws a FieldAccessException on Mono with High stripping. + - name: Disable DependencyConflict + run: ./test/Scripts.Integration.Test/add-dependency-conflict.ps1 -Disable - name: Configure Sentry run: ./test/Scripts.Integration.Test/configure-sentry.ps1 -UnityPath "$env:UNITY_PATH" -Platform Windows diff --git a/src/Sentry.Unity.Editor/MonoLinkerProcessor.cs b/src/Sentry.Unity.Editor/MonoLinkerProcessor.cs new file mode 100644 index 000000000..006dcf3d9 --- /dev/null +++ b/src/Sentry.Unity.Editor/MonoLinkerProcessor.cs @@ -0,0 +1,42 @@ +using System.IO; +using UnityEditor; +using UnityEditor.Build; +using UnityEditor.Build.Reporting; +using UnityEditor.UnityLinker; + +namespace Sentry.Unity.Editor; + +/// +/// On Mono, `HttpWebRequest` initializes the configuration system, which creates its host and the `machine.config` +/// section types via reflection. The UnityLinker can't see that and strips them on higher stripping levels, breaking +/// the HTTP transport. Unity ignores `link.xml` files inside packages, so we provide the rules at build time instead. +/// +internal class MonoLinkerProcessor : IUnityLinkerProcessor +{ + internal const string LinkXml = + """ + + + + + + + + + """; + + public int callbackOrder => 0; + + public string? GenerateAdditionalLinkXmlFile(BuildReport report, UnityLinkerBuildPipelineData data) + { + var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(report.summary.platformGroup); + if (PlayerSettings.GetScriptingBackend(namedBuildTarget) != ScriptingImplementation.Mono2x) + { + return null; + } + + var path = Path.Combine(data.inputDirectory, "Sentry.Unity.link.xml"); + File.WriteAllText(path, LinkXml); + return path; + } +} diff --git a/test/IntegrationTest/CommonTestCases.ps1 b/test/IntegrationTest/CommonTestCases.ps1 index 4940ef69c..02da2e883 100644 --- a/test/IntegrationTest/CommonTestCases.ps1 +++ b/test/IntegrationTest/CommonTestCases.ps1 @@ -28,6 +28,10 @@ $CommonTestCases = @( Set-ItResult -Skipped -Because "DependencyConflict is not installed on Unity 2021 + WebGL" return } + if ($env:SENTRY_TEST_SCRIPTING_BACKEND -eq "mono") { + Set-ItResult -Skipped -Because "DependencyConflict is not installed on Mono" + return + } $RunResult.Output | Where-Object { $_ -match "DependencyConflict: FAILED" } | Should -BeNullOrEmpty -Because "the DependencyConflict package threw at runtime - assembly aliasing likely regressed" From f63fa95f7da5142858c3a3213882731c3b8a908e Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Sat, 19 Sep 2026 00:38:40 +0900 Subject: [PATCH 2/2] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5193e948..3d7891d1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- The SDK now preserves the types Mono's HTTP stack needs, so events are sent when using `Mono` with a high managed stripping level ([#2858](https://github.com/getsentry/sentry-unity/pull/2858)) + ### Dependencies - Bump .NET SDK from v6.10.0 to v6.11.0 ([#2850](https://github.com/getsentry/sentry-unity/pull/2850))