-
-
Notifications
You must be signed in to change notification settings - Fork 2
fix: MeaiFunction type handling added more robust codes #29
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e101bac
fix: Json Schema Generation, used System.Text.Json JsonSchema generat…
e289da0
fix: warning suppressions
315af73
feat: Added FunctionTool attribute, which can be used to convert indi…
36cf256
feat: Added GoogleFunctionTool optional parameters in GenerateJsonSch…
904bbf0
Merge branch 'tryAGI:main' into main
gunpal5 6bfd9b7
Merge remote-tracking branch 'origin/main'
1ebee3f
Updated README.md
46a569b
fix: schema generation
d245705
Merge remote-tracking branch 'origin/main'
8071875
removed uncessary variable
234c61e
feat: Added M.E.A.I AIFunction generation
d8a5f36
Simplify description retrieval in SchemaSubsetHelper.
4075971
Refactor MeaiFunction.cs for improved readability
28da355
Refactor MeaiFunction to enhance clarity and functionality.
8830a3f
Update GoogleFunctionTool type references in generator
6243888
fix: Native AOT for Method Function Tools
972b9c5
Merge remote-tracking branch 'origin/main'
b49d3d2
Add snapshot files for ToolsJsonSerializerContext tests
e30dd35
Disable unused test method in SnapshotTests
d896319
Merge remote-tracking branch 'origin/main'
5de972c
Merge remote-tracking branch 'origin/main'
8c68191
fix: MeaiFunction ignoring simple values types arguments
b9e53e0
remove unused codes.
0d1df7a
Merge remote-tracking branch 'origin/main'
45eaf37
fix: MeaiFunction Type handling, added more robust codes.
9ba450e
suppressed IL2026, IL3050 for Reflection based type resolver
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
...Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.PropertyNames.g.received.cs
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.PropertyNames.g.verified.cs
This file was deleted.
Oops, something went wrong.
96 changes: 0 additions & 96 deletions
96
...hodFunction#ToolsJsonSerializerContext.SampleFunctionTool_NoReturnAsyncArgs.g.received.cs
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...hodFunction#ToolsJsonSerializerContext.SampleFunctionTool_NoReturnAsyncArgs.g.verified.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Added reflection fallback with explicit warning
The code includes a fallback to reflection-based serialization with explicit warning comments about AOT compatibility issues. While this provides good backward compatibility, it may lead to runtime errors in AOT environments.
Verify whether this reflection fallback is actually needed or if all scenarios can be covered by passing proper JsonSerializerOptions with type information. If reflection is truly needed, consider adding a feature flag to disable it in AOT environments.
🌐 Web query:
💡 Result:
To handle
System.Text.Jsonserialization effectively in AOT compilation environments, follow these best practices:1. Use Source Generators
Leverage
System.Text.Jsonsource generators to avoid reflection, which isn't AOT-compatible. Source generators precompute serialization logic at compile time, ensuring type metadata isn't trimmed.Example setup:
This eliminates runtime reflection and supports trimming/Native AOT[1][3][7][10].
2. Define a
JsonSerializerContextCreate a context class annotated with
[JsonSerializable]for all serializable types:Register it globally in ASP.NET Core:
This ensures type information is preserved during trimming[2][13][14].
3. Avoid Reflection-Based APIs
Disable reflection defaults to enforce AOT safety:
This throws
InvalidOperationExceptionif reflection is accidentally used[10].4. Handle Polymorphism with Attributes
Use
[JsonPolymorphic]and[JsonDerivedType]for AOT-safe inheritance:This replaces reflection-based type resolution[12][7].
5. Configure Serialization Options via Attributes
Set options at compile time using
JsonSourceGenerationOptions:This avoids runtime configuration overhead[10][13].
6. Handle Enums as Strings
Use
JsonStringEnumConverter<TEnum>for AOT-compatible enum serialization:Avoid the non-generic
JsonStringEnumConverter[7][10].7. Follow Model Constraints
List<T>,HashSet<T>, andDictionary<TKey, TValue>[1].8. Performance and Size Optimization
System.Text.Json[5][9].Example: AOT-Compatible Serialization
Output includes AOT-safe type discriminators:
{ "$type": "book", "title": "The Book", "author": "The Author" }By adopting these practices, you ensure compatibility with AOT/trimmed environments while maintaining performance and type safety[1][7][10][13].
Citations:
Action Required: Address Reflection Fallback for AOT Compatibility
The reflection-based fallback in use at
src/libs/CSharpToJsonSchema/MeaiFunction.cs(lines 144–150) poses a risk in AOT environments where runtime reflection is unsupported. Given best practices for System.Text.Json in AOT scenarios—such as leveraging source generators and predefining aJsonSerializerContext—relying on reflection can lead to runtime errors. If you must retain this fallback for backward compatibility, please consider one of the following actions:JsonSerializerOptions(e.g., with source-generated type metadata) to eliminate the risk in AOT environments.