semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: Exception is thrown with auto-function calling after upgrading to latest SK Nuget packages (version 1.4.0)

Open deepinderdeol opened this issue 2 years ago • 13 comments

This is where exception is thrown, the code was working fine with v1 of SK:

var executionSettings = new OpenAIPromptExecutionSettings() { ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions, Temperature = 0.0, }; var response = await chatCompletionService.GetChatMessageContentAsync(_skChatHistory, executionSettings, kernel);

Exception:

System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'System.Memory.Data, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Source=Microsoft.SemanticKernel.Connectors.OpenAI

StackTrace: at Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIFunction.ToFunctionDefinition() at Microsoft.SemanticKernel.Connectors.OpenAI.ToolCallBehavior.KernelFunctions.ConfigureOptions(Kernel kernel, ChatCompletionsOptions options) at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.CreateChatCompletionsOptions(OpenAIPromptExecutionSettings executionSettings, ChatHistory chatHistory, Kernel kernel, String deploymentOrModelName) at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.d__29.MoveNext() at Microsoft.SemanticKernel.ChatCompletion.ChatCompletionServiceExtensions.d__2.MoveNext()

deepinderdeol avatar Feb 23 '24 19:02 deepinderdeol

@deepinderdeol Thanks for reporting this issue. Could you please specify version of .NET SDK and Semantic Kernel you are using? Did you try to include System.Memory.Data v8 assembly directly into your project?

dmytrostruk avatar Feb 26 '24 09:02 dmytrostruk

I am using .NET sdk version 8.0.101

I only see the exception with latest SK version 1.4.0 - Tried with version 1.3.1 and do not get any exception

Have not tried including System.Memory.Data in the project.

deepinderdeol avatar Feb 26 '24 17:02 deepinderdeol

@deepinderdeol I just created empty console application and added Microsoft.SemanticKernel package version 1.4.0. I tried to execute the code with function calling, as you provided in issue description, and in my case it's working as expected. In my setup, I use .NET SDK 8.0.102.

There is a possibility that your solution pre-loads System.Memory.Data with other version than 8.0.0. In order to understand which dependency version is used in your solution, try to run dotnet list package --include-transitive and check version of System.Memory.Data. In case if version of this package is lower than 8.0.0, try to include this package directly in project where you use Semantic Kernel and let me know if that resolves an issue for you. Thank you!

dmytrostruk avatar Feb 27 '24 11:02 dmytrostruk

We are going to eliminate the System.Memory.Data dependency.

Related https://github.com/microsoft/semantic-kernel/issues/5226

markwallace-microsoft avatar Feb 28 '24 09:02 markwallace-microsoft

Thanks for looking into this @dmytrostruk @markwallace-microsoft

deepinderdeol avatar Feb 28 '24 16:02 deepinderdeol

@deepinderdeol, thanks for reporting the issue. May I ask you to provide a console app that reproduces the issue?

SergeyMenshykh avatar Mar 05 '24 09:03 SergeyMenshykh

@SergeyMenshykh I have not tried in a console app. We are using SK in an extension/add-in for our application . I will try a console app and let you know if the issue is reproducible there.

deepinderdeol avatar Mar 06 '24 06:03 deepinderdeol

@SergeyMenshykh I have confirmed that issue is non-repro in a console app. Have not yet been able to figure out why we are seeing the exception in our app...version 1.3.1 works okay. Issue is only with 1.4 and 1.5 Will update if/when I find something.

deepinderdeol avatar Mar 08 '24 01:03 deepinderdeol

@SergeyMenshykh one of my colleagues found this information - hope this helps in figuring out the problem:

I'm seeing the exception when loading the System.Client.Model.dll If I open the System.Client.Model.dll in ILSpy it shows a reference to the 1.0.2.0 version of the System.Memory.Data assembly

image

deepinderdeol avatar Mar 11 '24 00:03 deepinderdeol

Hi @deepinderdeol , ILSpy displays the version of the System.Memory.Data assembly with which the System.ClientModel assembly was built. However, just because it was built with System.Memory.Data v1.0.2 does not guarantee that v1.0.2 will be used when referenced by a hosting application. The package dependency resolution process is responsible for deciding the version to use.

I would recommend checking the package manager logs/output to see if there is any information regarding the System.Memory.Data package. Additionally, look at the project.assets.json file in your project's obj folder to see which other dependencies use the System.Memory.Data package, as well as their versions. Use this information in conjunction with the dependency resolution rules mentioned above to troubleshoot the issue.

SergeyMenshykh avatar Mar 11 '24 13:03 SergeyMenshykh

Thanks @SergeyMenshykh - we will check what you suggested.

This is the project.assets.json file: project.assets.json

Fyi - here is the load order of modules:

Loaded 'C:\Users<User-Folder>\AppData\Local\ESRI\ArcGISPro\AssemblyCache{e340dbb1-7bf4-442b-a2fd-2360be06b336}\Microsoft.SemanticKernel.Connectors.OpenAI.dll'. Loaded 'C:\Users<User-Folder>\AppData\Local\ESRI\ArcGISPro\AssemblyCache{e340dbb1-7bf4-442b-a2fd-2360be06b336}\Microsoft.SemanticKernel.Core.dll'. Loaded 'C:\ArcGIS\bin\Microsoft.Bcl.AsyncInterfaces.dll'. Loaded 'C:\Users<User-Folder>\AppData\Local\ESRI\ArcGISPro\AssemblyCache{e340dbb1-7bf4-442b-a2fd-2360be06b336}\Microsoft.Extensions.DependencyInjection.Abstractions.dll'. Loaded 'C:\Users<User-Folder>\AppData\Local\ESRI\ArcGISPro\AssemblyCache{e340dbb1-7bf4-442b-a2fd-2360be06b336}\Microsoft.Extensions.DependencyInjection.dll'. Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.2\System.Threading.Tasks.Extensions.dll'. Loaded 'C:\Users<User-Folder>\AppData\Local\ESRI\ArcGISPro\AssemblyCache{e340dbb1-7bf4-442b-a2fd-2360be06b336}\Microsoft.Extensions.Logging.Abstractions.dll'. Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.2\System.Security.Cryptography.X509Certificates.dll'. Loaded 'C:\Users<User-Folder>\AppData\Local\ESRI\ArcGISPro\AssemblyCache{e340dbb1-7bf4-442b-a2fd-2360be06b336}\System.ClientModel.dll'. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00000063ADB760F0. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00000063ADB760F0. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00000063ADB760F0. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00000063ADB760F0. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00000063ADB760F0. Exception thrown at 0x00007FFC736D5B0C in ArcGISPro.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown: 'System.IO.FileNotFoundException' in Microsoft.SemanticKernel.Connectors.OpenAI.dll Could not load file or assembly 'System.Memory.Data, Version=1.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

deepinderdeol avatar Mar 11 '24 15:03 deepinderdeol

@SergeyMenshykh fyi - the issue is fixed with the new packages - version 1.6.1

We have not made any changes on our side to fix this, so I assume something changed in the new packages? Hopefully we won't run into this problem again, but it would be good to know what the issue/change was.

deepinderdeol avatar Mar 14 '24 01:03 deepinderdeol

@SergeyMenshykh fyi - the issue is fixed with the new packages - version 1.6.1

We have not made any changes on our side to fix this, so I assume something changed in the new packages? Hopefully we won't run into this problem again, but it would be good to know what the issue/change was.

@deepinderdeol, thanks for letting us know that the issue is resolved in the new version of SK. The reason for this, most likely, is that we removed the dependency on the System.Memory.Data package in order to minimize the number of dependencies the SemanticKernel.Abstractions package has.

As for the issue you experienced, it is quite difficult to determine the root cause without being able to reproduce it.

SergeyMenshykh avatar Mar 14 '24 13:03 SergeyMenshykh