Skip to content
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

.Net: SemanticKernel package was not working in Winforms .NetFramework. #9755

Closed
ChidanandMurugaiah opened this issue Nov 19, 2024 · 5 comments
Assignees
Labels
.NET Issue or Pull requests regarding .NET code

Comments

@ChidanandMurugaiah
Copy link

ChidanandMurugaiah commented Nov 19, 2024

Describe the bug

We are utilizing the Microsoft.SemanticKernel package in a .NET Framework 4.8 Winforms sample to retrieve responses from ChatGPT. However, when invoking kernel.GetRequiredService(), it consistently returns null. As a result, we are unable to use the ChatCompletionService to fetch AI responses. Notably, the same code functions correctly in a .NET80 environment.

To Reproduce
Steps to reproduce the behavior:

  1. Run the sample
  2. Click Initialize button

Expected behavior
Sample needs to be run properly without exception.

Screenshots
Image

Sample Link - SemanticKernel (2).zip

Platform

  • OS:Windows 11
  • IDE: VS2022 version 17.12.0
  • Language: C#
  • Source:Microsoft.SemanticKernel package version 1.21.1

Additional context
We saw that this package was compatible for WPF .NetFramework.

@ChidanandMurugaiah ChidanandMurugaiah added the bug Something isn't working label Nov 19, 2024
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Nov 19, 2024
@github-actions github-actions bot changed the title SemanticKernel package was not working in Winforms .NetFramework. .Net: SemanticKernel package was not working in Winforms .NetFramework. Nov 19, 2024
@RogerBarreto
Copy link
Member

RogerBarreto commented Nov 19, 2024

@ChidanandMurugaiah, can you check if this works with our latest version? 1.29

Please provide more details about the stack trace you getting.

We had a bug 1 month ago related to Null reference exception when using function calling and can be related to your example

@ChidanandMurugaiah
Copy link
Author

@RogerBarreto,

1) can you check if this works with our latest version? 1.29

  • When we try to install the latest version of the KS package we are facing the below issue.
    Image

2) Please provide more details about the stack trace you getting.

Below is the Stack trace

at Microsoft.SemanticKernel.ChatCompletion.ChatCompletionServiceExtensions.GetChatMessageContentsAsync(IChatCompletionService chatCompletionService, String prompt, PromptExecutionSettings executionSettings, Kernel kernel, CancellationToken cancellationToken)
at Microsoft.SemanticKernel.ChatCompletion.ChatCompletionServiceExtensions.d__1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at SemanticKernel.AIService.d__10.MoveNext() in D:\Samples\Winforms\SemanticKernel\Form1.cs:line 57


3) We had a bug 1 month ago related to Null reference exception when using function calling and can be related to your example

#9313

  • We referred the query you mentioned but it was not similar to our problem. The same code works in .Net80 sample but not works in .NetFramework sample.

@RogerBarreto
Copy link
Member

RogerBarreto commented Nov 21, 2024

@ChidanandMurugaiah Thanks for the added context.

For the first item to successfully install in .Net Framework you need to download those dependencies manually because they are still in pre-release state.

Go to nuget package and download the Microsoft.Extensions.VectorData.Abstractions before installing SemanticKernel package and you will succeed.

Image

If the error persists for our latest version let me know and feel free to close this issue if the problem is solved.

Thanks.

@ChidanandMurugaiah
Copy link
Author

ChidanandMurugaiah commented Nov 25, 2024

@RogerBarreto, Now, I am able to install the latest version of Microsoft.SemanticKernal package but for that I need to install the below packages manually.

  • Microsoft.Extensions.VectorData.Abstractions
  • Azure.AI.OpenAI
  • Microsoft.Extensions.AI.Abstractions

Because these packages are in pre-release. So, when installing the SK package, these package not installed automatically in .NetFramework

Let me come to the point, even after installing the latest version of the SK, the issue still occurs.

@RogerBarreto
Copy link
Member

RogerBarreto commented Nov 25, 2024

@ChidanandMurugaiah I download your application demo and Identified that the problem on the Null actually is happening because you are calling an async method as it was synchronous.

Since there's no asynchronous task executing within your Initialize method, remove the async from it, and gpt won't be null anymore.

Image

I updated the project also to the latest version 1.30, installing the packages individually and was able to get the result with no problem.

Image

@github-project-automation github-project-automation bot moved this from Sprint: In Progress to Sprint: Done in Semantic Kernel Nov 25, 2024
@RogerBarreto RogerBarreto removed bug Something isn't working follow up Issues that require a follow up from the community. labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: Done
Development

No branches or pull requests

3 participants