Repository navigation
Conversation
Sets IsAotCompatible on the three libraries, which turns on the trimming, single-file and AOT analyzers for them, and fixes the 11 places they flag: - ConfigManager reads Config.js through source-generated JSON metadata (ConfigJsonContext) built from SerializerOptions, and falls back to AppContext.BaseDirectory instead of Assembly.Location, which is empty in a single-file or native AOT app. - EnumHelper.GetFlags and CharacterOptionExtensions no longer call Enum.GetValues(Type), which has to create an enum array at runtime. - The [Ephemeral], [SendOnLogin] and [AssessmentProperty] lookups declare that they read the enum's public fields. - AttributeExtensions.GetAttributeOfType suppresses IL2075: trimming never removes an enum's literal fields. - The DatLoader loggers use typeof instead of MethodBase.GetCurrentMethod(). No behaviour change for ACE.Server. ConfigManager.SerializerOptions is unchanged and still serves the callers that use reflection. Co-Authored-By: Claude Fable 5.2 <[email protected]>
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 problem
ACE.Common, ACE.Entity and ACE.DatLoader target net10.0 since #4562, but a program that uses them cannot be published trimmed or as native AOT. With the trimming and AOT analyzers turned on, master's build flags 11 places in them:
ACE.Common/ConfigManager.cs:64JsonSerializer.Deserialize<T>(string, JsonSerializerOptions)needs reflectionACE.Common/ConfigManager.cs:41Assembly.Locationis empty in a single-file appACE.Common/Extensions/EnumHelper.cs:14Enum.GetValues(Type)creates an array of the enum type at run timeACE.Entity/Enum/CharacterOption.cs:188ACE.Entity/Enum/AttributeExtensions.cs:8GetType().GetMember()on a type the trimmer cannot seeAssessmentProperties.cs:19,EphemeralProperties.cs:19,SendOnLoginProperties.cs:19(inACE.Entity/Enum/Properties)typeof(T).GetFields()on a type parameter with no annotationDatDatabase.cs:15,DatManager.cs:11,Entity/AnimationHook.cs:14(inACE.DatLoader)MethodBase.GetCurrentMethod()Three of them fail at run time. A console program that uses the three libraries, published as native AOT against master (see Testing), gets:
ConfigManager.InitializethrowsInvalidOperationException: Reflection-based serialization has been disabled for this application.Config.jsin the working directory, the one next to the executable is not found ("missing configuration file"), becauseAssembly.Locationis empty.EnumHelper.GetFlagsthrowsNotSupportedException: 'ACE.Entity.Enum.CharacterOptions1[]' is missing native code or metadata.The fix
<IsAotCompatible>true</IsAotCompatible>in the three project files. It turns on the trimming, single-file and AOT analyzers for them, so code that breaks this later shows up as a build warning, and it marks the assemblies as trimmable. Then the 11 places:Config.jsis read through source-generated JSON metadata.ConfigJsonContext(new, internal) declaresMasterConfiguration.ConfigManager.Initializebuilds the context from a copy ofConfigManager.SerializerOptions, so the settings (comments, trailing commas, numbers as strings) still come from that one place.SerializerOptionsitself is unchanged: ACE.Server uses it with reflection for the starter gear, the mod metadata and the first-run setup.Config.jsisAppContext.BaseDirectory, instead of the folder ofAssembly.GetExecutingAssembly().Location.EnumHelper.GetFlagsusesEnum.GetValuesAsUnderlyingTypeandEnum.ToObjectinstead ofEnum.GetValues(Type). It returns the same values in the same order.CharacterOptionExtensionsusesEnum.GetValues<CharacterOption>().AssessmentProperties,EphemeralPropertiesandSendOnLoginProperties: the type parameter of their privateGetValuesgets[DynamicallyAccessedMembers(PublicFields)]. The code is unchanged.AttributeExtensions.GetAttributeOfTypegets[UnconditionalSuppressMessage]for IL2075. It takes anySystem.Enum, so the analyzer cannot know the type. The lookup is safe because trimming never removes the literal fields of an enum. The runtime suppresses the same kind of warning for the same reason inType.GetEnumData("Literal fields on enums can never be trimmed"). The native AOT run below checks it.typeof(DatDatabase),typeof(DatManager)andtypeof(AnimationHook), the type thatMethodBase.GetCurrentMethod().DeclaringTypereturned.Behaviour
Config.js: the application's base directory instead of the folder that holds ACE.Common.dll. They are the same folder whenever ACE.Common.dll sits next to the executable, as it does in the solution's build and publish output.IsAotCompatibleon the libraries changes nothing in how it is built or run.Testing
On a Linux x64 VM (Ubuntu 26.04, .NET SDK 10.0.115) on 2026-11-29, against master 055a66c.
A check program (a console program, not part of this PR) references the three libraries and prints what they return:
Config.js.example; a file with comments, trailing commas, numbers as strings, a null section, an unknown property and its ownPreloadedLandblocks; and an invalid file, for which it prints the exception;Config.jsfound next to the executable, from a working directory without one;GetFlagsfor 11 values, everyCharacterOptionwith its two attributes,GetDescriptionforPropertyAttributeandPropertyAttribute2nd, and the 22[Ephemeral],[SendOnLogin]and[AssessmentProperty]sets;GetFlagsfor every enum type in the three assemblies (227 types, 49,317 calls, compared by hash), and usesSerializerOptionswith reflection before and afterInitialize.CharacterOption.cs, which only the build analyzer flags. The three failures listed under The problem.The native AOT builds use
PublishAotwith the three assemblies asTrimmerRootAssemblyitems andTrimmerSingleWarn=false. The compiler then compiles all of their code, not only what the program calls, and lists each warning.Solution build: 16 warnings on master and with this PR, the same list (13 CA1416 in
Texture.cs, 3 CA2022 inDatReader.cs).Test projects: the same results on master and with this PR, test by test, with the same failure messages.
All 17 failures are files that are not on this machine: the dat files under
C:\Turbine\Asheron's Call, and theConfig.js,Config.js.exampleandstarterGear.jsonthat the test setups look for.Not verified
Texture's bitmap code uses System.Drawing.Common, which is Windows-only. It compiled as native AOT without a warning, but it was not run.ConfigManager.Initializeon this machine: they fail in their setup first, on master too. The check program is what covers the config change.Files
Source/ACE.Common/ACE.Common.csprojSource/ACE.Common/ConfigJsonContext.cs(new)Source/ACE.Common/ConfigManager.csSource/ACE.Common/Extensions/EnumHelper.csSource/ACE.Entity/ACE.Entity.csprojSource/ACE.Entity/Enum/AttributeExtensions.csSource/ACE.Entity/Enum/CharacterOption.csSource/ACE.Entity/Enum/Properties/AssessmentProperties.csSource/ACE.Entity/Enum/Properties/EphemeralProperties.csSource/ACE.Entity/Enum/Properties/SendOnLoginProperties.csSource/ACE.DatLoader/ACE.DatLoader.csprojSource/ACE.DatLoader/DatDatabase.csSource/ACE.DatLoader/DatManager.csSource/ACE.DatLoader/Entity/AnimationHook.cs🤖 Generated with Claude Code