From 3652c9b105ccf15fe73dfb15a6803ae3bba29d6f Mon Sep 17 00:00:00 2001 From: John Karam <168653085+johnkaram02@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:22:32 +0000 Subject: [PATCH] .Net: Use parameter default value when a null argument targets a non-nullable value type When a KernelArguments value is null and the method parameter is a non-nullable value type with a default value, KernelFunctionFromMethod tried to convert null and threw ArgumentOutOfRangeException. OpenAI strict mode makes optional parameters nullable, so models send null for them and the call fails. Fall back to the parameter's default value in that case. --- .../Functions/KernelFunctionFromMethod.cs | 6 ++++-- .../Functions/KernelFunctionFromMethodTests1.cs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dotnet/src/SemanticKernel.Core/Functions/KernelFunctionFromMethod.cs b/dotnet/src/SemanticKernel.Core/Functions/KernelFunctionFromMethod.cs index 9385ae02bcaf..4dc83cb46c7d 100644 --- a/dotnet/src/SemanticKernel.Core/Functions/KernelFunctionFromMethod.cs +++ b/dotnet/src/SemanticKernel.Core/Functions/KernelFunctionFromMethod.cs @@ -697,8 +697,10 @@ private static (Func { actual = val; }); + + // Act + await sut.InvokeAsync(this._kernel, new() { ["val"] = null }); + + // Assert + Assert.Equal(5, actual); + } + [Fact] public async Task ItShouldMarshalArgumentsOfReferenceTypeAsync() {