Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGrainReferenceActivatorProvider exception with interfaces written in F# #8977

Open
pkese opened this issue May 5, 2024 · 3 comments
Open

Comments

@pkese
Copy link

pkese commented May 5, 2024

I've checked out the F# sample app and found out that interfaces in that sample app are written in C#.

Since there's not much point in using F# while being restricted to C# types (one can't use F# types in C# interfaces), I rewrote that assembly in F#.

IHelloGrain.fs

namespace HelloWorldInterfaces

open System.Threading.Tasks
open Orleans

type IHelloGrain =
    inherit IGrainWithIntegerKey
    abstract member SayHello : message:string -> ValueTask<string>

HelloWorldInterfaces.fsproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="IHelloGrain.fs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Orleans.Sdk" Version="8.0.0" />
  </ItemGroup>
</Project>

Problem is that after applying the above change (and fixing reference paths from .csproj to .fsproj), now I'm getting:

Unhandled exception. System.InvalidOperationException: Unable to find an IGrainReferenceActivatorProvider for grain type hello
   at Orleans.GrainReferences.GrainReferenceActivator.CreateActivator(GrainType grainType, GrainInterfaceType interfaceType) in /_/src/Orleans.Core/GrainReferences/GrainReferenceActivator.cs:line 85
   at Orleans.GrainReferences.GrainReferenceActivator.CreateReference(GrainId grainId, GrainInterfaceType interfaceType) in /_/src/Orleans.Core/GrainReferences/GrainReferenceActivator.cs:line 54
   at Orleans.GrainFactory.GetGrain(Type interfaceType, IdSpan grainKey, String grainClassNamePrefix) in /_/src/Orleans.Core/Core/GrainFactory.cs:line 217
   at Orleans.GrainFactory.GetGrain[TGrainInterface](Int64 primaryKey, String grainClassNamePrefix) in /_/src/Orleans.Core/Core/GrainFactory.cs:line 51
   at Program.<Main>$(String[] args) in /home/peter/work/org/dotnet-samples/orleans/FSharpHelloWorld/HelloWorld/Program.cs:line 21
   at Program.<Main>(String[] args)

How can I fix the above problem?
How can I declare interfaces with F# types in Orleans project?

@pkese
Copy link
Author

pkese commented May 5, 2024

I've added a commit for the above change to make it easier to test:
dotnet/samples@c132eb8

@pkese pkese changed the title IGrainReferenceActivatorProvider exception with interfaces written in F# IGrainReferenceActivatorProvider exception with interfaces written in F# May 5, 2024
@mikescandy
Copy link

isn't that by design? If i remember correctly, orleans source generator only works on c# projects. The way we do it is we have a c# project that references the f# one and the sdk, and has a c# file with something like this

[assembly: GenerateCodeForDeclaringAssembly(typeof(Any type from the f# project with grain interfaces))]

@ReubenBond
Copy link
Member

ReubenBond commented Jun 10, 2024

@pkese what @mikescandy wrote is right. The missing line is likely [assembly: GenerateCodeForDeclaringAssembly(typeof(HelloWorldInterfaces.IHelloGrain))]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants