Some AOT warning
I am publishing a console app that depends on ZLogger as NativeAOT, and I encountered the following warnings. I’m not sure if you’re willing to resolve them.
ILC : Trim analysis warning IL2026: ZLogger.MessageSequence.ToString(MagicalBox,Span`1<InterpolatedStringParameter>): Using member 'System.Text.Json.JsonSerializer.Serialize(Object,Type,JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext,
or make sure all of the required types are preserved. [test.csproj]
ILC : AOT analysis warning IL3050: ZLogger.MessageSequence.ToString(MagicalBox,Span`1<InterpolatedStringParameter>): Using member 'System.Text.Json.JsonSerializer.Serialize(Object,Type,JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for nati
ve AOT applications. [test.csproj]
ILC : Trim analysis warning IL2026: ZLogger.MessageSequence.ToString(MagicalBox,Span`1<InterpolatedStringParameter>): Using member 'System.Text.Json.JsonSerializer.Serialize<IEnumerable>(IEnumerable,JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSeria
lizerContext, or make sure all of the required types are preserved. [test.csproj]
ILC : AOT analysis warning IL3050: ZLogger.MessageSequence.ToString(MagicalBox,Span`1<InterpolatedStringParameter>): Using member 'System.Text.Json.JsonSerializer.Serialize<IEnumerable>(IEnumerable,JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source genera
tion for native AOT applications. [test.csproj]
ILC : Trim analysis warning IL2026: ZLogger.Internal.MagicalBox.ReaderCache.JsonSerialize<T>(MagicalBox,Int32,Utf8JsonWriter,JsonSerializerOptions): Using member 'System.Text.Json.JsonSerializer.Serialize<T>(Utf8JsonWriter,T,JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a
JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved. [test.csproj]
ILC : AOT analysis warning IL3050: ZLogger.Internal.MagicalBox.ReaderCache.JsonSerialize<T>(MagicalBox,Int32,Utf8JsonWriter,JsonSerializerOptions): Using member 'System.Text.Json.JsonSerializer.Serialize<T>(Utf8JsonWriter,T,JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use Syst
em.Text.Json source generation for native AOT applications. [test.csproj]
ILC : AOT analysis warning IL3050: ZLogger.Internal.EnumDictionary`1..cctor(): Using member 'System.Enum.GetValues(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. It might not be possible to create an array of the enum type at runtime. Use the GetValues<TEnum> overload or the GetValuesAsUnderlyingType method instead. [test.csproj]
Based on my current knowledge, it is challenging to fully support NativeAOT.
Sandbox/ConsoleApp/Program.cs
uncomment line 50
logger.LogInformation("aiueo {id:0,0000} ", 100);
publish with aot
<PublishAot>true</PublishAot>
ConsoleApp will crash
`
Process terminated. Failed to create generic virtual method implementation
Declaring type: ZLogger.Formatters.PlainTextZLoggerFormatter
Method name: FormatLogEntry
Instantiation:
Argument 00000000: ZLogger.ZLoggerEntry1<ZLogger.LogStates.StringFormatterLogState1<Microsoft.Extensions.Logging.FormattedLogValues>>
`