Skip to content

Conversation

Stepami
Copy link
Contributor

@Stepami Stepami commented May 5, 2025

Using JsonSerializer.Serialize{TValue}(TValue, JsonTypeInfo{TValue}) overload to avoid IL warnings

Info:

  • Validly 1.1.5

Still have trouble publishing AOT:

    ILC : Trim analysis warning IL2026: Validly.ValidationMessage.<>c.<.ctor>b__0_0(Object): Using member 'System.Text.Json.JsonSerializer.Serialize<Object>(Object,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.
    ILC : AOT analysis warning IL3050: Validly.ValidationMessage.<>c.<.ctor>b__0_0(Object): Using member 'System.Text.Json.JsonSerializer.Serialize<Object>(Object,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 native AOT applications.

@Stepami
Copy link
Contributor Author

Stepami commented May 6, 2025

@Hookyns what is package version update strategy now?

@Hookyns
Copy link
Owner

Hookyns commented May 7, 2025

I'd like to run some tests related to this. For now, I published it as 1.1.6-rc.1

@Stepami
Copy link
Contributor Author

Stepami commented Jul 10, 2025

@Hookyns any updates?

@Hookyns
Copy link
Owner

Hookyns commented Jul 10, 2025

I'd like to do that this weekend. I also want to update the documentation - especially, to document the ASP.NET Core extension.

@Stepami
Copy link
Contributor Author

Stepami commented Aug 12, 2025

@Hookyns have you succeeded in running some tests?
Having IL warnings absent in release nuget would be really great!

@Hookyns
Copy link
Owner

Hookyns commented Aug 25, 2025

@Stepami do you use Validly with AOT, and does it work for you? I’m concerned it cannot work because the <IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible> condition is always false. This happens since it targets netstandard2.0, which is not considered compatible with net7.0 (the check returns false).

I’ll add all the new AOT-compatible targets (net7.0; net8.0; net9.0; net10.0), so that should resolve the issue. Hopefully, this will show some noticeable improvement in the benchmark.

EDIT:

<PropertyGroup>
    <ValueAotCompatible>$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))</ValueAotCompatible>
</PropertyGroup>
<Target Name="BuildInfo" AfterTargets="Build">
    <Message Text="$(TargetFramework) is AOT compatible: $(ValueAotCompatible)" />
</Target>
BuildInfo:
         netstandard2.0 is AOT compatible: False
         net10.0 is AOT compatible: True
         net7.0 is AOT compatible: True
         net8.0 is AOT compatible: True
         net9.0 is AOT compatible: True

@Stepami
Copy link
Contributor Author

Stepami commented Sep 3, 2025

@Hookyns i do, but IL trimming warnings must be absent

@Stepami
Copy link
Contributor Author

Stepami commented Sep 10, 2025

@Hookyns hi!
Will this PR be merged?

Can't use the lib in my projects because of the wrong STJ API call under the hood in 1.1.5.

Really need this fix 🙏

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

Successfully merging this pull request may close these issues.

2 participants