From adeb8e47c72b731a88db2a201b7752ebc2fffa12 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 10 Nov 2026 13:24:22 +0100 Subject: [PATCH] test: Save Xbox game config atomically in build hook The Xbox build preprocessor saved `ScarlettGame.config` in place with `XmlDocument.Save`, which holds the file open exclusively while writing. Unity watches the game config and re-reads it on change, so a read that lands mid-write fails with a sharing violation. Unity logs that as an error, and `BuildOptions.StrictMode` turns it into a failed build: ```text Failed to read Game Config file, System.IO.IOException: Sharing violation on path <...> ``` Save to the project's `Temp` folder instead and swap the complete file in with `File.Replace`, so the watcher never sees a partially written file. Failed run: https://github.com/getsentry/sentry-xbox/actions/runs/42793976990/job/129758551877 --- .../Editor/XboxPersistentLocalStorage.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Scripts.Integration.Test/Editor/XboxPersistentLocalStorage.cs b/test/Scripts.Integration.Test/Editor/XboxPersistentLocalStorage.cs index 11c9e64d5..dcb64fba6 100644 --- a/test/Scripts.Integration.Test/Editor/XboxPersistentLocalStorage.cs +++ b/test/Scripts.Integration.Test/Editor/XboxPersistentLocalStorage.cs @@ -38,7 +38,11 @@ public void OnPreprocessBuild(BuildReport report) pls.InnerXml = "1122"; - doc.Save(configPath); + // Unity watches the game config and re-reads it on change. Saving in place can make that read hit + // a sharing violation mid-write, which fails the build in strict mode. Swap in a complete file instead. + var tempPath = Path.Combine("Temp", configName); + doc.Save(tempPath); + File.Replace(tempPath, configPath, null); Debug.Log($"XboxPersistentLocalStorage: Configured PersistentLocalStorage in {configName}"); } }