anthropics / anthropics/anthropic-sdk-csharp

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

Aperta
#258 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
322
Fork
105
Merge medio
1g 6h
PR unite (30g)
9

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.