You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.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.
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
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.
The text was updated successfully, but these errors were encountered:
github-actionsbot
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
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.Task
1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.Teams.AI.State.TurnState.<LoadStateAsync>d__26.MoveNext() at Microsoft.Teams.AI.Application
1.<_OnTurnAsync>d__66.MoveNext()at Microsoft.Teams.AI.Application
1.<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.ValueTaskAwaiter
1.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
Screenshots
Screenshot is attached.
Platform
Microsoft.SemanticKernel" Version="1.47.0"
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.
The text was updated successfully, but these errors were encountered: