When I import orleans.dll which version 1.4.0 into unity3d project and initialize GrainClient, I encoutered a problem following printed in log:
KeyNotFoundException: Unable to find a type named Orleans.Providers.IProvider, Orleans, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null
Orleans.Runtime.CachedTypeResolver.ResolveType (System.String name) (at
Orleans.Runtime.TypeUtils.ResolveReflectionOnlyType (System.String assemblyQualifiedName) (at
Orleans.Runtime.TypeUtils.ToReflectionOnlyType (System.Type type) (at
System.Linq.Enumerable+WhereSelectArrayIterator2[TSource,TResult].MoveNext () (at <2450f0d4d6c64a5398b72705936129ee>:0) System.Linq.Buffer1[TElement]..ctor (System.Collections.Generic.IEnumerable1[T] source) (at <2450f0d4d6c64a5398b72705936129ee>:0) System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable1[T] source) (at <2450f0d4d6c64a5398b72705936129ee>:0)
Orleans.Runtime.AssemblyLoaderCriteria.LoadTypesAssignableFrom (System.Type[] requiredTypes) (at
Orleans.Runtime.AssemblyLoaderCriteria.LoadTypesAssignableFrom (System.Type requiredType) (at
Orleans.OutsideRuntimeClient.LoadAdditionalAssemblies () (at
Orleans.OutsideRuntimeClient..ctor (Orleans.Runtime.Configuration.ClientConfiguration cfg, System.Boolean secondary) (at
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143)
Orleans.GrainClient.InternalInitialize (Orleans.Runtime.Configuration.ClientConfiguration config) (at
Orleans.GrainClient.Initialize (Orleans.Runtime.Configuration.ClientConfiguration config) (at
TestOrleansClient+
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143)
System.Runtime.CompilerServices.AsyncMethodBuilderCore.
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:72)
UnityEngine.UnitySynchronizationContext.Exec () (at C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:36)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:56)
It seems that orleans.dll is not fully compatiable with Mono.
This is the code I wrote:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using Orleans;
using Orleans.Runtime.Configuration;
using TestOrleansInterfaces;
public class TestOrleansClient : MonoBehaviour {
// Use this for initialization
void Start () {
awaitGrain ();
}
async private void awaitGrain() {
var config = ClientConfiguration.LocalhostSilo();
GrainClient.Initialize(config);
ITestGrain grain = GrainClient.GrainFactory.GetGrain<ITestGrain>(0);
string name = await grain.GetGrainName();
UnityEngine.Debug.Log ("Get Grain Name:" + name);
}
}
Then I tried to dig into code and comment the code at line 135 of file OutsideRuntimeClient.cs, and then it works, but I don't know whether it is safe or not. The version of the orleans source codes I use is 1.4.0, the code I comment is following(see the last line):
public OutsideRuntimeClient(ClientConfiguration cfg, bool secondary = false)
{
this.typeCache = new TypeMetadataCache();
this.assemblyProcessor = new AssemblyProcessor(this.typeCache);
this.grainFactory = new GrainFactory(this, this.typeCache);
if (cfg == null)
{
Console.WriteLine("An attempt to create an OutsideRuntimeClient with null ClientConfiguration object.");
throw new ArgumentException("OutsideRuntimeClient was attempted to be created with null ClientConfiguration object.", "cfg");
}
this.config = cfg;
if (!LogManager.IsInitialized) LogManager.Initialize(config);
StatisticsCollector.Initialize(config);
SerializationManager.Initialize(cfg.SerializationProviders, cfg.FallbackSerializationProvider);
this.assemblyProcessor.Initialize();
logger = LogManager.GetLogger("OutsideRuntimeClient", LoggerType.Runtime);
appLogger = LogManager.GetLogger("Application", LoggerType.Application);
BufferPool.InitGlobalBufferPool(config);
this.handshakeClientId = GrainId.NewClientId();
tryResendMessage = TryResendMessage;
unregisterCallback = msg => UnRegisterCallback(msg.Id);
try
{
// I comment this line
// LoadAdditionalAssemblies();
......
Has anyone successfully incorporated an Orleans Client into Unity3d?
Orleans is not designed to be called directly from an external (untrusted) client such as a mobile device running a Unity3d application.
Our advice is that instead of calling from Unity3d into Orleans, add a Web Frontend built using a technology such as ASP.NET and call into Orleans from that frontend.
@ReubenBond here at INSANE we are currently using Unity3D instances as servers of our MMORPG. We are planning to use Orleans as our Entity State Layer and the Unity3D support would be awesome! Do you guys still have no plans for it?
We are doing the same as Izaiats where we are running headless Unity3D instances as servers for our game and having the ability to cut out the middleman (a front end ASP.NET server for example) would simplify our stack considerably @ReubenBond I second this being possible
@reefbarman Actually, the Unity 2018.x is fully compatible with Orleans 2.0... Using the 4.x NET Runtime ;) If you need some help setting things up, please tell me!
If you interested, here is a link to the Unity forum that shows ou progress on our task: https://forum.unity.com/threads/netenginex-mmo-server-architecture-using-c-and-unity.532460/
Most helpful comment
@ReubenBond here at INSANE we are currently using Unity3D instances as servers of our MMORPG. We are planning to use Orleans as our Entity State Layer and the Unity3D support would be awesome! Do you guys still have no plans for it?