简体   繁体   English

找不到颗粒接口的实现 class

[英]Cannot find an implementation class for grain interface

I have 2 interfaces in my assembly, and 2 grains that implement them.我的程序集中有 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(){}
}

This call to grain of type IGrain2 throws:这个调用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.

I do not get why this exception happens, since both interfaces and grains are in the same assembly.我不明白为什么会发生这种异常,因为接口和颗粒都在同一个程序集中。 Can anyone provide any idea?任何人都可以提供任何想法吗?

There are two possible solutions for this case:这种情况有两种可能的解决方案:

  1. Adding MSBuild package reference:添加 MSBuild package 参考:
 <PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.4.2">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 </PackageReference>
  1. In your SiloBuilder in Startup you could use the ConfigureApplicationParts method to register the Assembly.在 Startup 的 SiloBuilder 中,您可以使用ConfigureApplicationParts方法来注册程序集。 This is not recommended but can be done like this:不建议这样做,但可以这样做:
siloBuilder.ConfigureApplicationParts((Action<IApplicationPartManager>)(parts =>
  {  
     parts.AddApplicationPart(typeof(SomeGrain).Assembly).WithReferences();
  }));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM