Skip to content

.Net: Bug: Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIChatMessageContent - A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. #11820

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

Open
MavhengeleMpho opened this issue Apr 30, 2025 · 0 comments
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@MavhengeleMpho
Copy link

We are using Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIChatMessageContent for our chatHistory, it works fine when saving history as strings, the challenge comes when we try to save messages from AuthorRole tool and when there is toolCalls involved, this happens when we use the plugin to get data from the apis/ database, we are able to save messages from other AuthorRoles its the Tool AuthorRole that introduces issues, and the tool authorRoles are added outside of our codebase, initially we where removing the messages in the chathistory with tool authorRole but now we must put them back since we starting to work towards building agents calling other agents to avoid loosing context we put the tool messages back in but we get the below error:

System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Something went wrong when loading state: Unable to find a constructor to use for type Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIChatMessageContent. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path '**************************.$values[1].ToolCalls'.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.Teams.AI.State.TurnState.<LoadStateAsync>d__26.MoveNext() at Microsoft.Teams.AI.Application1.<_OnTurnAsync>d__66.MoveNext()
at Microsoft.Teams.AI.Application1.<OnTurnAsync>d__63.MoveNext() at Microsoft.Bot.Builder.MiddlewareSet.<ReceiveActivityWithStatusAsync>d__3.MoveNext() at Microsoft.Bot.Builder.BotAdapter.<RunPipelineAsync>d__23.MoveNext() at Microsoft.Bot.Builder.BotAdapter.<RunPipelineAsync>d__23.MoveNext() at Microsoft.Bot.Builder.CloudAdapterBase.<ProcessActivityAsync>d__22.MoveNext() at Microsoft.Bot.Builder.CloudAdapterBase.<ProcessActivityAsync>d__21.MoveNext() at Microsoft.Bot.Builder.Integration.AspNet.Core.CloudAdapter.<ProcessAsync>d__4.MoveNext() .Controllers.BotController.<PostAsync>d__5.MoveNext() in D:\SourceControl\2025\\Controllers\BotController.cs:line 41 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskResultExecutor.<Execute>d__0.MoveNext() at System.Runtime.CompilerServices.ValueTaskAwaiter1.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<g__Logged|12_1>d.MoveNext()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<g__Awaited|10_0>d.MoveNext()

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
TeamsAIException: Something went wrong when loading state: Unable to find a constructor to use for type Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIChatMessageContent. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'adfd964c-955f-48dd-afcc-dddf578af169.$values[1].ToolCalls'.

Inner Exception 2:
JsonSerializationException: Unable to find a constructor to use for type Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIChatMessageContent. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'adfd964c-955f-48dd-afcc-dddf578af169.$values[1].ToolCalls'.

To Reproduce
Just have toolCalls from Kernel Functions in your chatHistory

Expected behavior
It must serialize and deserialize the chatHistory, be able to keep it in AppState and not break

Image

Screenshots
Screenshot is attached.

Platform

  • Language: C#, API
  • Source: Microsoft.SemanticKernel.Abstractions" Version="1.47.0" and
    Microsoft.SemanticKernel" Version="1.47.0"
  • AI model: OpenAI:GPT-4o
  • IDE: Visual Studio
  • OS: . Windows

Additional context
All we are trying to do is, save the messages objects and metadata from the AuthorRole tool to the chatHistory same as we also save user and assistant messages to the chatHistory and be able to load them back From AppState ->Conversation State->chatHistory and use them again when sending the messages back to the GPT fro context.

@MavhengeleMpho MavhengeleMpho added the bug Something isn't working label Apr 30, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Apr 30, 2025
@github-actions github-actions bot changed the title Bug: Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIChatMessageContent - A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. .Net: Bug: Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIChatMessageContent - A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Apr 30, 2025
@RogerBarreto RogerBarreto moved this from Bug to Sprint: Planned in Semantic Kernel May 6, 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: Planned
Development

No branches or pull requests

3 participants