Skip to content

.Net: Bug: Failed to serialize arguments to Json #11600

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

Closed
mhackermsft opened this issue Apr 16, 2025 · 4 comments · Fixed by #11626
Closed

.Net: Bug: Failed to serialize arguments to Json #11600

mhackermsft opened this issue Apr 16, 2025 · 4 comments · Fixed by #11626
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@mhackermsft
Copy link

Describe the bug
Exact same issue as #11511 but the issue is not resolved by using a specific SK or Microsoft.Extensions.AI package.

I am running into the exact same issue with Semantic Kernel 1.46.0 and ModelContextProtocol .01.0-Preview.9. I have the Microsoft.Extensions.AI 9.4.0-preview.1.25207.5 installed.

Error message:
Microsoft.SemanticKernel.KernelFunction[0]
Function playwright-playwright_get arguments: Failed to serialize arguments to Json
System.NotSupportedException: JsonTypeInfo metadata for type 'Microsoft.SemanticKernel.KernelArguments' was not provided by TypeInfoResolver of type 'Microsoft.SemanticKernel.AbstractionsJsonContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type type)
at Microsoft.SemanticKernel.KernelFunctionLogMessages.LogFunctionArgumentsInternal(ILogger logger, String pluginName, String functionName, KernelArguments arguments, JsonSerializerOptions jsonSerializerOptions)

Seeing similar message with another MCP server:
Microsoft.SemanticKernel.KernelFunction[0]
Function spotify-SpotifyPlayback arguments: Failed to serialize arguments to Json
System.NotSupportedException: JsonTypeInfo metadata for type 'Microsoft.SemanticKernel.KernelArguments' was not provided by TypeInfoResolver of type 'Microsoft.SemanticKernel.AbstractionsJsonContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type type)
at Microsoft.SemanticKernel.KernelFunctionLogMessages.LogFunctionArgumentsInternal(ILogger logger, String pluginName, String functionName, KernelArguments arguments, JsonSerializerOptions jsonSerializerOptions)

Here are my project references:

all runtime; build; native; contentfiles; analyzers; buildtransitive

Expected behavior
The tool is successfully called and the LLM can use it to generate a response.

Platform

  • Language: C#
  • Source: [e.g. NuGet package version 0.1.0, pip package version 0.1.0, main branch of repository]
  • AI model: gpt-4o
  • IDE: Visual Studio
  • OS: Windows
@mhackermsft mhackermsft added the bug Something isn't working label Apr 16, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Apr 16, 2025
@github-actions github-actions bot changed the title Bug: Failed to serialize arguments to Json .Net: Bug: Failed to serialize arguments to Json Apr 16, 2025
@SergeyMenshykh
Copy link
Member

Hi @mhackermsft,

Semantic Kernel 1.46.0 is built against the ModelContextProtocol .01.0-Preview.8 nuget package. SK was just updated to the latest ModelContextProtocol .01.0-Preview.9 today - #11582. We may release a new SK version either at the end of this week or early next week.

Meanwhile, to get unblocked, consider downgrading to the ModelContextProtocol .01.0-Preview.8 nuget package.

@mhackermsft
Copy link
Author

I downgraded to the ModelContextProtocol .01.0-Preview.8 nuget package but I am still getting the same error:

Microsoft.SemanticKernel.KernelFunction[0]
Function playwright-playwright_press_key arguments: Failed to serialize arguments to Json
System.NotSupportedException: JsonTypeInfo metadata for type 'Microsoft.SemanticKernel.KernelArguments' was not provided by TypeInfoResolver of type 'Microsoft.SemanticKernel.AbstractionsJsonContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type type)
at Microsoft.SemanticKernel.KernelFunctionLogMessages.LogFunctionArgumentsInternal(ILogger logger, String pluginName, String functionName, KernelArguments arguments, JsonSerializerOptions jsonSerializerOptions)

@SergeyMenshykh
Copy link
Member

Hi @mhackermsft, please try downgrading to the ModelContextProtocol.01.0-Preview.7 NuGet package. If that does not work, could you please create a console app that reproduces this issue, as it is not reproducible on our side?

@mhackermsft
Copy link
Author

downgrading to 7 didn't resolve the issue. I have a demo that reproduces the issue consistently at: https://github.com/mhackermsft/SKMCPDemo.

<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.4" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.46.0" />
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" Version="1.46.0" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="1.46.0" />
<PackageReference Include="ModelContextProtocol" Version="0.1.0-preview.9" />

The MCPClient project attempts to use a Playwright MCP server from: https://github.com/executeautomation/mcp-playwright

Downgrading the ModelContextProtocol version does not resolve the issue.

trce: Microsoft.SemanticKernel.KernelFunction[0]
Function playwright-playwright_fill arguments: Failed to serialize arguments to Json
System.NotSupportedException: JsonTypeInfo metadata for type 'Microsoft.SemanticKernel.KernelArguments' was not provided by TypeInfoResolver of type 'Microsoft.SemanticKernel.AbstractionsJsonContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type type)
at Microsoft.SemanticKernel.KernelFunctionLogMessages.LogFunctionArgumentsInternal(ILogger logger, String pluginName, String functionName, KernelArguments arguments, JsonSerializerOptions jsonSerializerOptions)

@SergeyMenshykh SergeyMenshykh moved this from Bug to Sprint: In Review in Semantic Kernel Apr 17, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 17, 2025
### Motivation and Context

Fixes the issue of function arguments serialization of SK functions
created from functions of `M.E.AI.AIFunction` type.

Fixes: #11600
@SergeyMenshykh SergeyMenshykh moved this from Sprint: In Review to Sprint: Done in Semantic Kernel Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: Done
Development

Successfully merging a pull request may close this issue.

3 participants