dotnet / dotnet/orleans

Using a grain before WebApplication.Run throws NRE

Open
#8,636 0 comments 0 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

```cs
using Orleans.Runtime;

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseOrleans(siloBuilder =>
{
siloBuilder.UseLocalhostClustering();
siloBuilder.AddMemoryGrainStorage("tests");
});
var app = builder.Build();
await app.Services
.GetRequiredService().GetGrain(Guid.NewGuid())
.Test();

interface ITestGrain : IGrainWithGuidKey { Task Test(); }
class Test { }

class TestGrain : Grain, ITestGrain
{
private readonly IPersistentState _state;

public TestGrain([PersistentState(stateName: "test", storageName: "tests")] IPersistentState state)
{
_state = state;
}

public Task Test() => Task.CompletedTask;
}
```

I understand from https://github.com/dotnet/orleans/issues/8240 that the silo hosted service needs to be initialized before using Orleans but what do you think about throwing a more explicit exception such as "Orleans was not initialized...".

Contributor guide

Open the contributing guide

Research direction

Start with the supplied WebApplication reproduction, focusing on the GetRequiredService() call made before WebApplication.Run. Trace Orleans initialization at that entry point and verify that using a grain before initialization produces an explicit Orleans-not-initialized exception rather than an NRE.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.