Unable to add data source to chat client with C# 7.3

Alex Kienzle 5 Reputation points
2024-06-21T14:21:38.3366667+00:00

I am working on a UWP application that interacts with Azure OpenAI chat client. I have been using the latest Nuget package (2.0.0-beta.2) and have had some success creating and using a chat client. I am now trying to add a data source to my chat client, but it seems that there is no way to create a data source with the C# language version I am currently using. I have been using this sample as a guide:
https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/openai/Azure.AI.OpenAI/tests/Samples/02_Oyd.cs

C# 7.3 does not support init-only setters, which seem to be a requirement to create one of the AzureChatDataSource objects. Since I cannot upgrade my UWP project to version 9.0 and I cannot find a workaround, I seem to be stuck. Other features of this library seem to otherwise be supported, so I suspect this may have been an oversight.

The attached image shows the issue I am having.

User's image

Syntactically, there doesn't seem to be any other way to create a data source. Is there something I am missing? Please advise. Thanks!

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,995 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,189 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. gekka 9,586 Reputation points MVP
    2024-06-22T07:24:12.0333333+00:00

    To resolve this error, you need to add the LangVersion to your *.csproj file.

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
      <PropertyGroup>
    
        <LangVersion>9</LangVersion> 
    

  2. Bruce (SqlWork.com) 66,056 Reputation points
    2024-08-15T15:53:19.2566667+00:00

    the nuget package does not support the .net 4.* framework used by UWP. as UWP was never upgraded to .net core, you will need to pick another approach. probably the easiest is to create a REST API with a .net 8, and call from your UWP application.

    as you will find more features unavailable, at some point you should upgrade your UWP application to a modern framework.

    note: 7.3 is the highest version of C# support by net 4.8. in the .net core world, an update to the c# language requires a new minimum runtime version. version 9 requires .net5+, version 12 requires .net8+.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.