.Net: Bug: Microsoft.SemanticKernel.Yaml is incompatible with current YamlDotNet, causing TypeLoadException at runtime
Describe the bug
Using KernelFunctionYaml.FromPromptYaml() to deserialize YAML to an SK function in an existing codebase, with an existing dependency on YamlDotNet latest version (16.1.3).
The call to KernelFunctionYaml.FromPromptYaml() results in a TypeLoadException with the message:
Method 'ReadYaml' in type 'Microsoft.SemanticKernel.PromptExecutionSettingsTypeConverter' from assembly 'Microsoft.SemanticKernel.Yaml, Version=1.20.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3' does not have an implementation.
It appears to be a breaking change with YamlDotNet 16.0.0, released 7/14/2024, specifically a change to the method signature of IYamlTypeConverter.ReadYaml()
To Reproduce Steps to reproduce the behavior:
- Have a project that references
YamlDotNet16.1.3 andMicrosoft.SemanticKernel.Yaml - Call
KernelFunctionYaml.FromPromptYaml()with valid (or invalid) YAML. - The
TypeLoadExceptionis thrown.
Expected behavior
The call to KernelFunctionYaml.FromPromptYaml() should parse the YAML and if it is valid, return a valid KernelFunction object.
Screenshots N/A
Platform
- OS: Windows
- IDE: Visual Studio 2022
- Language: .NET 8, C#
- Source: YamlDotNet 16.1.3, Microsoft.SemanticKernel.Yaml 1.20.0 - 1.21.1
Additional context The problem occurred while using Microsoft.SemanticKernel.Yaml < 1.20.0 but was not investigated until now.
@jphorv-bdo thanks for reporting this. @markwallace-microsoft will take a look.
I have the same issue.
I'm using Semantic Kernel in combination with Microsoft Orleans. Both Microsoft.SemanticKernel.Yaml (1.30.0) and Microsoft.Orleans.Hosting.Kubernetes (9.0.0) have a dependency on YamlDotNet.
A call to the CreateFunctionFromPromptYaml method throws the exception @jphorv-bdo mentioned above if you use YamlDotNet version 16.0.0 or later. YamlDotNet version 15.3.0 still works, however unfortunately, Microsoft.Orleans.Hosting.Kubernetes (9.0.0) has a dependency on YamlDotNet >= 16.0.0.
@markwallace-microsoft this is still open with YamlDotNet 16.3.0 and Microsoft.SemanticKernel.Yaml 1.33.0
UPDATE: I realised my issue was that my project uses the FastEndpoints packages, which are referencing YamlDotNet. My workaround was to downgrade FastEndpoint packages to a version that references YamlDotNet 15.3.0.
I'm having the same issue. Is there any workaround? should we downgrade the SK package? I'm not adding the YamlDotNet package explicitely, just using these packages:
<PackageReference Include="Microsoft.SemanticKernel" Version="1.35.0" />
<PackageReference Include="Microsoft.SemanticKernel.Yaml" Version="1.35.0" />
and when calling:
var myYaml = EmbeddedResource.Read("my.yaml");
var myFunction = _kernel.CreateFunctionFromPromptYaml(myYaml);
I'm getting the error:
Method 'ReadYaml' in type 'Microsoft.SemanticKernel.PromptExecutionSettingsTypeConverter' from assembly 'Microsoft.SemanticKernel.Yaml, Version=1.35.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3' does not have an implementation.
at Microsoft.SemanticKernel.KernelFunctionYaml.ToPromptTemplateConfig(String text)
at Microsoft.SemanticKernel.KernelFunctionYaml.FromPromptYaml(String text, IPromptTemplateFactory promptTemplateFactory, ILoggerFactory loggerFactory)
at Microsoft.SemanticKernel.PromptYamlKernelExtensions.CreateFunctionFromPromptYaml(Kernel kernel, String text, IPromptTemplateFactory promptTemplateFactory)
Am I doing something wrong? seems odd that we can´t use Yaml prompts with latest SK versions...
Thanks!
I was using FastEndpoints.Swagger and downgraded to 5.30.0. Looks like the specific error was made in YamlDotNet 4 months ago. You can use dotnet nuget why yamldotnet find the version 16.1.3 and downgrade to something >4 months ago (from writing this of course).
@tamaw to be clear, there is no error in YamlDotNet. That project changed an interface and bumped their major version number appropriately. Semantic Kernel must respond by either:
- updating the YamlDotNet dependency to be compatible with 16.x and making that the minimum version.
- setting the YamlDotNet dependency's "max allowed version" to < 16
@markwallace-microsoft Although https://github.com/microsoft/semantic-kernel/pull/12641 has been merged, I imagine this issue will re-occur when YamlDotNet v17 is released. Can we set the YamlDotNet version to be >= 16.3.0 and < 17?
@markwallace-microsoft Although #12641 has been merged, I imagine this issue will re-occur when YamlDotNet v17 is released. Can we set the YamlDotNet version to be >= 16.3.0 and < 17?
FWIW I looked at YamlDotNet for signs of WIP and don't see much activity. Unless you see something I missed, there is nothing that suggest this will happen w/ YamlDotNet v17. Version 16 just happened to have the kind of change that is incompatible - a change to a public interface method.