I have a solution in .NET 7 version. I am using Orleans 7.0.2 version in this solution.
I have 3 projects in my solution named Contracts, Grains and ConsoleApp.
I have IStock.cs interface in my Contracts project:
public interface IStock : IGrainWithIntegerKey
{
Task<int> Get();
}
In my Grains project, I have the StockGrain.cs class and it uses the IStock.cs interface:
public class StockGrain : Grain, IStock
{
public Task<int> Get()
{
return Task.FromResult(10);
}
}
ConsoleApp project references 2 other projects. I am using the sample code as below in the Program.cs file:
var host = Host.CreateDefaultBuilder(args)
.UseOrleans(builder =>
{
builder.UseLocalhostClustering();
}).Build();
await host.StartAsync();
var client = host.Services.GetRequiredService<IGrainFactory>();
var grain = client.GetGrain<IStock>(1);
await host.StopAsync();
When I run ConsoleApp I get the following error:
Unhandled exception. System.ArgumentException: Could not find an implementation for interface Contracts.IStock
at Orleans.GrainInterfaceTypeToGrainTypeResolver.GetGrainType(GrainInterfaceType interfaceType)
In Orleans 7 version, the Grain class I implemented cannot be found.
Install Microsoft.Orleans.Sdk into your Contracts and Grains projects. Without it code generation doesn't work.