dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.07k stars 2.03k forks source link

Asp.net 5 - Cannot find an implementation class for grain interface #1189

Closed elmortega closed 8 years ago

elmortega commented 8 years ago

I´m getting this exception:

An unhandled exception occurred while processing the request.

ArgumentException: Cannot find an implementation class for grain interface: OrleansWebAppTest.Models.IHello. Make sure the grain assembly was correctly deployed and loaded in the silo. Loaded grain assemblies: file:///C:/Users/byrmanager/Documents/Visual Studio 2015/Projects/TemporalProjects/orleans/src/OrleansConsoleHost/bin/Debug/OrleansRuntime.DLL en Orleans.Runtime.TypeCodeMapper.GetImplementation(Type interfaceType, String grainClassNamePrefix) en C:\Users\byrmanager\Documents\Visual Studio 2015\Projects\TemporalProjects\orleans\src\Orleans\IDs\TypeCodeMapper.cs:línea 17

The public bool TryGetGrainClassData method in the GrainInterfaceMap.cs returns false as it doesn´t seem to be able to get an implementation for the provided interface as the this.typeToInterfaceData.TryGetValue(GetTypeKey(interfaceType, false), out interfaceData) method returns false

In my project.json:

"frameworks": { "dnx451": { "dependencies": { "Orleans": "1.0.0-", "OrleansProviders": "1.0.0-" } } },

richorama commented 8 years ago

Does the silo successfully load your assembly? You should it scan for assemblies at startup, it tells you if it found anything in each of the DLLs it looked in...

elmortega commented 8 years ago

How can I make sure the grain assembly was correctly deployed and loaded in the silo?

richorama commented 8 years ago

Orleans searches the directory where the host application is located, as well as the Applications sub-directory, and all directories under it.

elmortega commented 8 years ago

I thought I could just put my grain interfaces and implementation code in the webapp's model folder. but I guess that way the silo host wouldn't be able to load my grain classes, right?

elmortega commented 8 years ago

loadedAssemblies contains only one, the OrleansRuntime.DLL

richorama commented 8 years ago

How are you hosting the Orleans silos?

elmortega commented 8 years ago

Console Application http://dotnet.github.io/orleans/Step-by-step-Tutorials/Minimal-Orleans-Application

richorama commented 8 years ago

Are your grain assemblies in the bin\debug directory of the console application?

A convenient way of doing that is to add them as references and set them to copy locally.

richorama commented 8 years ago

did that fix the problem?

elmortega commented 8 years ago

It was solved when using the v1.1.0-VSIX project templates

asifshiraz commented 7 years ago

I'm facing the same problem. In my case, I'm initializing the TestCluster from inside a unit test's constructor. The Grain and GrainInterface projects are referenced by the Unit Tests and are available in the bin/x64/Debug folder of the Unit Tests project. Still, the Silo complains of not having the assembly loaded.

sergeybykov commented 7 years ago

@asifshiraz Can you open a separate issue with information about which version you are running. Are you grain classes public, BTW?

jamescarter-le commented 7 years ago

Be aware that if you have your grains in an .exe file and include this as a reference in your UnitTest project Orleans will not scan this assembly for Grains, they must be in a .dll file instead.

philrowan-mtb commented 7 years ago

I just came across this and found out my grain class was not inheriting Orleans.Grain and was only implementing my grain interface. Adding Orleans.Grain fixed it for me.

sergeybykov commented 7 years ago

A code analyzer could potentially help find such issues and produce warnings.

sq735 commented 6 years ago

I just came across this and found out my grain class was not inheriting Orleans.Grain and was only implementing my grain interface. Adding Orleans.Grain fixed it for me.

@philrowan-mtb thanks a lot

allenbrubaker commented 6 years ago

I was getting the same issue. I was properly using the grain interface type when attempting to obtain the grain implementation via the GrainFactory; however, I finally solved it by adding a reference to the nuget package: Microsoft.Orleans.OrleansCodeGenerator.Build in the silo, grains, and grain interfaces projects.

I think perhaps the error message should be a little more accurate or at least contain verbiage pertaining to the above nuget dependency requirement. Or better yet the silo should fail to startup and throw an exception.

sergeybykov commented 6 years ago

I finally solved it by adding a reference to the nuget package: Microsoft.Orleans.OrleansCodeGenerator.Build in the silo, grains, and grain interfaces projects.

There's no need to add it to the silo project.

fadingdust commented 5 years ago

Note: Microsoft.Orleans.CodeGenerator.MSBuild is a viable alternative to Microsoft.Orleans.OrleansCodeGenerator.Build