@@ -62,9 +62,10 @@ public MeaiFunction(Tool tool, Func<string, CancellationToken, Task<string>> cal
6262 }
6363
6464
65- #pragma warning disable IL2026 , IL3050 // Reflection is used only when enabled
65+
6666 private JsonSerializerOptions InitializeReflectionOptions ( )
6767 {
68+ #pragma warning disable IL2026 , IL3050 // Reflection is used only when enabled
6869 if ( ! JsonSerializer . IsReflectionEnabledByDefault )
6970 throw new InvalidOperationException ( "JsonSerializer.IsReflectionEnabledByDefault is false, please pass in a JsonSerializerOptions instance." ) ;
7071
@@ -77,8 +78,9 @@ private JsonSerializerOptions InitializeReflectionOptions()
7778 TypeInfoResolver = new DefaultJsonTypeInfoResolver ( )
7879 } ;
7980 return _options ;
80- }
8181 #pragma warning restore IL2026 , IL3050 // Reflection is used only when enabled
82+ }
83+
8284
8385 /// <summary>
8486 /// Invokes the tool with the given arguments asynchronously.
@@ -134,25 +136,27 @@ protected virtual string GetArgsString(IEnumerable<KeyValuePair<string, object?>
134136 }
135137 else
136138 {
137- var type = args . Value ? . GetType ( ) ;
138- if ( type . IsPrimitive )
139- {
140- jsonObject [ args . Key ] = JsonValue . Create ( args . Value ) ;
141- }
142- else
143- {
139+ var type = args . Value ? . GetType ( ) ;
140+ // if(type.IsPrimitive)
141+ // {
142+ // jsonObject[args.Key] = JsonValue.Create(args.Value);
143+ // }
144+ // else
145+ // {
144146 if ( _options == null )
145147 {
148+ #pragma warning disable IL2026 , IL3050 // Reflection is used only when enabled
146149 //Fallback to Reflection
147150 //This will break the AOT, Hoping for the best, IChatClient implementation only send JSON classes
148151 //Or Developer is using the code generator
149152 _options = InitializeReflectionOptions ( ) ;
153+ #pragma warning disable IL2026 , IL3050 // Reflection is used only when enabled
150154 }
151155 var typeInfo = _options . GetTypeInfo ( type ) ;
152156
153157 var str = JsonSerializer . Serialize ( args . Value , typeInfo ) ;
154158 jsonObject [ args . Key ] = JsonNode . Parse ( str ) ;
155- }
159+ // }
156160 }
157161 }
158162
0 commit comments