我的程序集中有两个接口,以及实现它们的两个晶粒。
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
的晶粒的调用抛出:
Cannot find an implementation class for grain interface: [path].IGrain2 . Make sure the grain assembly was correctly deployed and loaded in the silo.
我不明白为什么会发生这种异常,因为界面和晶粒都在同一个程序集中。有人能提供任何想法吗?
这种情况有两种可能的解决方案:
- 添加MSBuild包引用:
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- 在启动中的SiloBuilder中,可以使用
ConfigureApplicationParts
方法注册程序集。不建议这样做,但可以这样做:
siloBuilder.ConfigureApplicationParts((Action<IApplicationPartManager>)(parts =>
{
parts.AddApplicationPart(typeof(SomeGrain).Assembly).WithReferences();
}));