dotnet / dotnet/orleans

Compilation error when a model property is declared using the required modifier

Open
#8,491 0 comments 2 reactions 0 assignees View on GitHub
Needs: triage :mag:
Dominant language
C#
Stars
10.9k
Forks
2.1k
Avg merge
14h 42m
Merged PRs (30d)
354

Description

I have a contract project (which will be shared as a nupkg with other services) referencing the following _Orleans_ pakcages:

```

```

I then have the following models defined as grain call messages:

```c#
[GenerateSerializer, Immutable]
public record Foo
{
[Id(0)] public required Bar Bar {get; init;}
[Id(1)] public required IReadOnlyList Bars {get; init;} = Array.Empty();
}

[GenerateSerializer, Immutable]
public sealed record class Bar(string Id);
```

However when building the project I get the following errors:

![image](https://github.com/dotnet/orleans/assets/16215744/292fe393-d73e-4ab8-8b6d-989349182208)

Removing the `required` keyword solves the problem however the modifier is used for other purposes (which I have not covered for brevity).

Contributor guide

Open the contributing guide

Research direction

Start by building the contract project with the Microsoft.Orleans.CodeGenerator, Microsoft.Orleans.Analyzers, and Microsoft.Orleans.Core.Abstractions 7.1.2 packages and capture the compiler diagnostics shown for Foo. Compare the generated serializer or analyzer behavior with and without required, and consider the issue resolved when the required declarations build successfully while preserving serialization for Bar and Bars.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.