fix: suppress ILLink trimmer warnings across osu.Game and osu.Desktop - #362
Merged
Merged
Conversation
Copilot created this pull request from a session on behalf of
winnerspiros
May 28, 2026 17:02
View session
winnerspiros
marked this pull request as ready for review
May 28, 2026 17:22
There was a problem hiding this comment.
Pull request overview
Suppresses ILLink/Roslyn trim-analyzer warnings across osu.Game and osu.Desktop by scoping suppressions to known reflection/dynamic call sites and fixing an attribute mismatch that produced a build error.
Changes:
- Fixed
RequiresUnreferencedCodeannotation mismatch on a virtual override by moving suppression to the specific call site (BackgroundDataStoreProcessor.LoadComplete()). - Added targeted suppressions for Newtonsoft.Json reflection,
Type.GetType/Activator.CreateInstance, and Realm migration dynamic binding. - Added/adjusted trimming annotations (
DynamicallyAccessedMembers) to align constructor contracts.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| osu.Game/IO/Serialization/JsonSerializableExtensions.cs | Adds unconditional IL2026 suppressions around Newtonsoft.Json-based serialization helpers. |
| osu.Game/IO/Serialization/Converters/TypedListConverter.cs | Suppresses IL2057/IL2072 around Type.GetType and Activator.CreateInstance. |
| osu.Game/IO/Serialization/Converters/SnakeCaseStringEnumConverter.cs | Suppresses IL2026 on converter construction due to Newtonsoft.Json reflection. |
| osu.Game/Database/RealmAccess.cs | Suppresses IL2026 for dynamic binding inside Realm migrations. |
| osu.Game/Database/BackgroundDataStoreProcessor.cs | Removes invalid override-level RUC annotation and suppresses IL2026 at the specific call site. |
| osu.Game/Configuration/SettingSourceAttribute.cs | Aligns DynamicallyAccessedMembers annotation on the 4-arg ctor parameter. |
| osu.Game/Configuration/ModSettingChangeTracker.cs | Suppresses IL2026 on constructor that calls reflection-based settings control creation. |
| osu.Desktop/Windows/GameplayWinKeyBlocker.cs | Suppresses IL3000 around WindowsKey.Disable/Enable scheduling. |
| osu.Desktop/Program.cs | Suppresses IL2026 around legacy IPC provider construction. |
| osu.Desktop/OsuGameDesktop.cs | Suppresses IL2026 around DiscordRichPresence component async load. |
| osu.Desktop/IPC/OsuWebSocketProvider.cs | Suppresses IL2026 around websocket message serialization via Newtonsoft.Json. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+15
to
25
| [UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "Newtonsoft.Json reflection usage is intentional and safe for non-trimmed targets.")] | ||
| public static string Serialize(this object obj) => JsonConvert.SerializeObject(obj, CreateGlobalSettings()); | ||
|
|
||
| [UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "Newtonsoft.Json reflection usage is intentional and safe for non-trimmed targets.")] | ||
| public static T Deserialize<T>(this string objString) => JsonConvert.DeserializeObject<T>(objString, CreateGlobalSettings()); | ||
|
|
||
| [UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "Newtonsoft.Json reflection usage is intentional and safe for non-trimmed targets.")] | ||
| public static void DeserializeInto<T>(this string objString, T target) => JsonConvert.PopulateObject(objString, target, CreateGlobalSettings()); | ||
|
|
||
| [UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "Newtonsoft.Json reflection usage is intentional and safe for non-trimmed targets.")] | ||
| public static JsonSerializerSettings CreateGlobalSettings() => new JsonSerializerSettings |
| { | ||
| public class SnakeCaseStringEnumConverter : StringEnumConverter | ||
| { | ||
| [UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "Newtonsoft.Json reflection usage is intentional and safe for non-trimmed targets.")] |
Comment on lines
+34
to
35
| [UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "SettingSourceAttribute uses reflection intentionally; callers on trimmed targets must ensure mod types are preserved.")] | ||
| public ModSettingChangeTracker(IEnumerable<Mod> mods) |
| applyMigrationsForVersion(migration, i); | ||
| } | ||
|
|
||
| [UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "Dynamic binding in realm migrations is intentional and safe for non-trimmed targets.")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The build emitted 1 error and 34 ILLink/Roslyn trim-analyzer warnings across Linux, Windows, macOS, and iOS jobs. The error was a
RequiresUnreferencedCodeannotation mismatch on a virtual override; the warnings were unannotated reflection/dynamic call sites.Changes
Annotation mismatch (error → warning → clean)
BackgroundDataStoreProcessor.LoadComplete(): removed[RequiresUnreferencedCode]from the override — baseDrawable.LoadComplete()carries no such annotation, making the pairing illegal. Replaced with#pragma warning disable IL2026scoped to the singleprocessScoresWithMissingStatistics()call site.SettingSourceAttribute4-param ctor: added[DynamicallyAccessedMembers(All)]to thedeclaringTypeparameter to match the 3-param ctor it delegates to.Newtonsoft.Json / reflection suppressions
JsonSerializableExtensions:[UnconditionalSuppressMessage("ILLink", "IL2026")]on all four methods — suppresses without propagating to every caller.SnakeCaseStringEnumConverterctor,ModSettingChangeTrackerctor: same pattern.OsuWebSocketProvider.broadcast,OsuGameDesktop.LoadComplete,Program: inline#pragma warning disable IL2026at the specific call sites.Type.GetType/Activator.CreateInstanceinTypedListConverter#pragma warning disable IL2057aroundType.GetType(typeName).#pragma warning disable IL2072aroundActivator.CreateInstance(type).Dynamic binding in
RealmAccessmigrations[UnconditionalSuppressMessage("ILLink", "IL2026")]onapplyMigrationsForVersion— covers alldynamic/Binder.GetMemberhits within that method.RequiresAssemblyFilesinGameplayWinKeyBlocker#pragma warning disable IL3000around theWindowsKey.Disable/Enablescheduler calls (Windows-only, never single-file).