TextControlBox-WinUI icon indicating copy to clipboard operation
TextControlBox-WinUI copied to clipboard

Ahead Of Time (AOT) Compatibility

Open ManuStone opened this issue 2 months ago • 1 comments

What in the code is not AOT-compliant

InputHandlerControl.cs: The class inherits from TextBox and overrides OnKeyDown, but it wasn't partial. The WinRT interop tools (CsWinRT) warn because they can't generate the necessary AOT code otherwise. I've fixed this; the class is now partial. I haven't separately tested whether this alone prevented a crash.

Example Solution internal partial class InputHanndlerControl : TextBox instead of internal class InputHanndlerControl : TextBox

SyntaxHighlightingRenderer.cs:82: JsonConvert.DeserializeObject from Newtonsoft.Json is not AOT-compliant. It builds, but GetSyntaxHighlightingFromJson is likely to fail at runtime under AOT. The solution would be System.Text.Json with a source generator (JsonSerializerContext). This isn't called during normal startup.

Example Solution

public class UserProfile { public string Username { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; }

using System.Text.Json.Serialization;

[JsonSourceGenerationOptions(WriteIndented = true)] [JsonSerializable(typeof(UserProfile))] internal partial class AppJsonContext : JsonSerializerContext {

}

var myProfile = new UserProfile { Username = "Anna", Email = "[email protected]" };

string jsonContext = JsonSerializer.Serialize(myProfile, AppJsonContext.Default.UserProfile); / string jsonInput = "{"Username":"Anna","Email":"[email protected]"}";

UserProfile? deserialized = JsonSerializer.Deserialize(jsonInput, AppJsonContext.Default.UserProfile);

ManuStone avatar Sep 28 '26 18:09 ManuStone

Fixed in #41

FrozenAssassine avatar Oct 24 '26 08:10 FrozenAssassine