Search code examples
c#monounity-game-engineremoting

mono in unity 3d and .net remoting


I am working on a Unity project where I need to work with a remoting client. I have created an interface class and I am using a remoting server in an other Unity project.

While the server is working without problems, the creation of the client fails with following exception:

System.TypeInitializationException: An exception was thrown by the type initializer for System.Runtime.Remoting.Channels.SocketCache ---> System.NotImplementedException: The requested feature is not implemented. at System.Threading.ThreadPool.UnsafeRegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, System.Object state, TimeSpan timeout, Boolean executeOnlyOnce) [0x00000] in :0

My code for the client:

MyRemotableObject remoteObject;

void Awake ()
{
    try
    {
        TcpChannel chan = new TcpChannel();
        ChannelServices.RegisterChannel(chan, false);
        remoteObject = (MyRemotableObject)Activator.GetObject(typeof(MyRemotableObject), "tcp://localhost:124/TargetShooterMenu");
    }
    catch (Exception e)
    {
        Debug.LogError(e.ToString());
    }
....

Does anyone know how to solve this problem? According to Mono FAQ, Mono should have remoting support. I am workin with Unity 3.5.1 (should have Mono 2.6.3) on a Windows 7 x64 Professional machine.

Thanks in advance


Solution

  • I am using Unity to do the exact same thing.

    First thing you have to do is change the player Api Compatibility Level from ".Net 2.0 subset" to ".Net 2.0"

    Next you have to get the 2.0 mono library "System.Runtime.Remoting.dll" from MonoDevelop

    Mine was located at "/Applications/Unity/MonoDevelop.app/Contents/Frameworks/Mono.framework/Libraries/mono/2.0/System.Runtime.Remoting.dll"

    place that into the "Assets/Plugins" folder and Unity will take care of dragging out the rest of the libraries.

    From then on out, it seems that remoting works without a hitch :)

    If you add the Remoting dll and build only to find an error like "But the dll is not allowed to be included or could not be found" then your still using ".Net 2.0 Subset"