@@ -62,13 +62,13 @@ private static MethodInfo GetMethod(string name)
6262 try
6363 {
6464 var sidecar = serviceProvider . GetService < IConversationSideCar > ( ) ;
65- var argTypes = args . Select ( x => x . GetType ( ) ) . ToArray ( ) ;
65+ var argTypes = args . Select ( x => x != null ? x . GetType ( ) : null ) . ToArray ( ) ;
6666 var sidecarMethod = sidecar ? . GetType ( ) ? . GetMethods ( BindingFlags . Public | BindingFlags . Instance )
6767 . FirstOrDefault ( x => x . Name == methodName
6868 && x . ReturnType == retType
6969 && x . GetParameters ( ) . Length == argTypes . Length
7070 && x . GetParameters ( ) . Select ( p => p . ParameterType )
71- . Zip ( argTypes , ( paramType , argType ) => paramType . IsAssignableFrom ( argType ) ) . All ( y => y ) ) ;
71+ . Zip ( argTypes , ( paramType , argType ) => IsParameterTypeMatch ( paramType , argType ) ) . All ( y => y ) ) ;
7272
7373 return ( sidecar , sidecarMethod ) ;
7474 }
@@ -78,6 +78,28 @@ private static MethodInfo GetMethod(string name)
7878 }
7979 }
8080
81+ private static bool IsParameterTypeMatch ( Type paramType , Type ? argType )
82+ {
83+ // If argument is null, check if parameter type is nullable
84+ if ( argType == null )
85+ {
86+ // Check if it's a nullable value type (e.g., int?)
87+ if ( paramType . IsGenericType && paramType . GetGenericTypeDefinition ( ) == typeof ( Nullable < > ) )
88+ {
89+ return true ;
90+ }
91+ // Check if it's a reference type (which are inherently nullable)
92+ if ( ! paramType . IsValueType )
93+ {
94+ return true ;
95+ }
96+ return false ;
97+ }
98+
99+ // Normal type matching
100+ return paramType . IsAssignableFrom ( argType ) ;
101+ }
102+
81103 private async Task < ( bool , object ? ) > CallAsyncMethod ( IConversationSideCar instance , MethodInfo method , Type retType , object [ ] args )
82104 {
83105 object ? value = null ;
0 commit comments