Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .github/workflows/test-build-windows-mono.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
42 changes: 42 additions & 0 deletions src/Sentry.Unity.Editor/MonoLinkerProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.IO;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.UnityLinker;

namespace Sentry.Unity.Editor;

/// <summary>
/// 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.
/// </summary>
internal class MonoLinkerProcessor : IUnityLinkerProcessor
{
internal const string LinkXml =
"""
<linker>
<assembly fullname="System.Configuration">
<type fullname="System.Configuration.ExeConfigurationHost" preserve="all"/>
</assembly>
<assembly fullname="System">
<namespace fullname="System.Net.Configuration" preserve="all"/>
</assembly>
</linker>
""";

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;
}
}
4 changes: 4 additions & 0 deletions test/IntegrationTest/CommonTestCases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading