anthropics / anthropics/anthropic-sdk-csharp

Unable to use Anthropic package from .Net Standard 2.0 environments due to the "get;init" properties

Offen
#258 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
322
Forks
105
Ø Merge
1 T. 6 Std.
Gemergte PRs (30 T.)
9

Beschreibung

The `Anthropic` package declares itself as compatible with .Net Standard 2.0.
In particular that means it [should work][1] in the classic .Net Framework 4.6.1 and later.
It does not.

It installs successfully, but it cannot be used because Visual Studio will refuse to touch any classes from it whose properties are declared as `{ get; init; }`. Starting with the `MessageCreateParams` class.

So trying to do the simple:

```cs
var parameters = new MessageCreateParams
{
Model = Model.ClaudeSonnet5,
MaxTokens = 2048,
...
};
```
will result in multiple of:

> Feature 'init-only setters' is not available in C# 7.3. Please use language version 9.0 or greater.

, one for each property of `MessageCreateParams` that you have touched.

The language version is set at 7.3 by Visual Studio based on the FW 4.7.1 used.

Here is a Stack Overflow question about this same problem, as applied to the CvsHelper library: https://stackoverflow.com/questions/66491591/after-update-to-vs-16-9-0-feature-init-only-setters-is-not-available-in-c-sha.

The authors of said library have reverted the `init` change; I believe you should too.

[1]: https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.