简体   繁体   中英

Cannot find a type code for an implementation class for grain interface

In microsoft orleans ( v0.9 Preview April 2014) , you may get this error when creating an azure web-api which references orleans grains:

Cannot find a type code for an implementation class for grain interface: 729000394.
Make sure the grain assembly was correctly deployed and loaded in the silo.

Here is some sample api code that may generate this error:

public class GrainController: ApiController
{

    public GrainControllerController() { 

    }


    public async Task<List<Model>> Get() {
        var grain = MyGrainFactory.GetGrain(0);
        return await grain.GetModels();
    }
}

Here's some grain code:

public class MyGrain: Orleans.GrainBase, IMyGrain
{
    public Task<List<Model>> GetModels()
    {
        return Task.FromResult(new List<Model>() { 

            new Model(){
                 name="my model name"
            }
        });
    }
}

public interface IMyGrain : Orleans.IGrain
{
    Task<List<Model>> GetModel();
}

To fix this:

You must reference your Grain implementation , as well as the interfaces in your web api. In Visual Studio 2013, you would do this by:

Solution Explorer > right-click your api project > references > add reference > solution > select both the interfaces and the implementations

This solution applies to Codename Orleans v0.9 Preview April 2014

Edit:

You may experience this error for another reason. We accidentally deleted this out of our .csproj file for our grains project.

<Import Project="$(OrleansSDK)\Binaries\OrleansClient\Orleans.SDK.targets" />

This causes multiple different errors, for example, your codegen.cs file may not be recompiled on a fresh build.

Also, you may have removed this from your .csproj file:

<PropertyGroup>
    <PostBuildEvent>
      if exist "$(OrleansSDK)\LocalSilo" (
      if not exist "$(OrleansSDK)\LocalSilo\Applications" (md "$(OrleansSDK)\LocalSilo\Applications")
      if not exist  "$(OrleansSDK)\LocalSilo\Applications\$(RootNamespace)" (md "$(OrleansSDK)\LocalSilo\Applications\$(RootNamespace)")
      copy /y *.dll  "$(OrleansSDK)\LocalSilo\Applications\$(RootNamespace)\"
      copy /y *.pdb  "$(OrleansSDK)\LocalSilo\Applications\$(RootNamespace)\"
      )
      if exist "$(OrleansSDK)\Binaries" (
      if not exist "$(OrleansSDK)\Binaries\Applications" (md "$(OrleansSDK)\Binaries\Applications")
      if not exist  "$(OrleansSDK)\Binaries\Applications\$(RootNamespace)" (md "$(OrleansSDK)\Binaries\Applications\$(RootNamespace)")
      copy /y *.dll "$(OrleansSDK)\Binaries\Applications\$(RootNamespace)\"
      copy /y *.pdb "$(OrleansSDK)\Binaries\Applications\$(RootNamespace)\"
      )
    </PostBuildEvent>
  </PropertyGroup>

This is what allows you to run your grains in your local silo. Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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