ZLogger icon indicating copy to clipboard operation
ZLogger copied to clipboard

Some AOT warning

Open vxzms opened this issue 1 year ago • 2 comments

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]

vxzms avatar Apr 04 '24 07:04 vxzms

Based on my current knowledge, it is challenging to fully support NativeAOT.

neuecc avatar Apr 05 '24 04:04 neuecc

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>>

`

qumeta avatar Apr 19 '24 03:04 qumeta