【问题标题】:Cannot find an implementation class for grain interface找不到grain接口的实现类
【发布时间】:2022-01-11 20:18:54
【问题描述】:

我的程序集中有 2 个接口,以及实现它们的 2 个颗粒。

public interface IGrain1:IGrainWithIntegerKey { void SomeMethod(); }
public interface IGrain2:IGrainWithIntegerKey { void SomeOtherMethod(); }

public Grain1:IGrain1
{
   public void SomeMethod()
   {
        var grain2=this.GrainFactory.GetGrain<IGrain2>([somekey]);
   }
}

public Grain2:IGrain2
{
       void SomeOtherMethod(){}
}

IGrain2 类型的grain 的调用会抛出:

Cannot find an implementation class for grain interface: [path].IGrain2 . Make sure the grain assembly was correctly deployed and loaded in the silo.

我不明白为什么会发生这种异常,因为接口和颗粒都在同一个程序集中。任何人都可以提供任何想法吗?

【问题讨论】:

  • 这个问题的答案几乎肯定在GrainFactory 之内,但没有提供。

标签: c# .net-assembly orleans


【解决方案1】:

这种情况有两种可能的解决方案:

  1. 添加 MSBuild 包参考:
 <PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.4.2">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 </PackageReference>
  1. 在启动时的 SiloBuilder 中,您可以使用 ConfigureApplicationParts 方法注册程序集。不建议这样做,但可以这样做:
siloBuilder.ConfigureApplicationParts((Action<IApplicationPartManager>)(parts =>
  {  
     parts.AddApplicationPart(typeof(SomeGrain).Assembly).WithReferences();
  }));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 2018-03-14
    • 2010-10-29
    • 2013-12-08
    • 1970-01-01
    • 2012-01-10
    相关资源
    最近更新 更多