Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some AOT warning #156

Open
vxzms opened this issue Apr 4, 2024 · 2 comments
Open

Some AOT warning #156

vxzms opened this issue Apr 4, 2024 · 2 comments

Comments

@vxzms
Copy link

vxzms commented Apr 4, 2024

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]
@neuecc
Copy link
Member

neuecc commented Apr 5, 2024

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

@qumeta
Copy link

qumeta commented Apr 19, 2024

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

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants