[Mono-list] mono and .net remoting again
mirek
miroslav.binas at cnl.tuke.sk
Tue Feb 6 08:48:58 EST 2007
hello
few days ago i wrote about my problem with .net remoting in mono. one of
the advice was to report a bug, but it seems, it's not a bug. so. i'll
try to describe the problem.
i am trying to create an application, that will have server side and it
will communicate with other nodes in the network in a created thread,
that will be running in each 10 seconds. so - the main application has
one thread for client communication. the problem is with the calling of
the remote objects from the thread - nothing happend (when i use timer)
and exception rise (when i create normal thread).
the code is as follows:
the remote object - class Test:
using System;
namespace remoting
{
public class Test : MarshalByRefObject
{
public Test()
{
}
public string Hello()
{
return( "hello cikos" );
}
}
}
the server code:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace remoting
{
class MainClass
{
public static void Main(string[] args)
{
TcpChannel chan = new TcpChannel( 11111 );
ChannelServices.RegisterChannel( chan );
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Test),
"Test",
WellKnownObjectMode.SingleCall );
System.Console.WriteLine( "Press the enter key to exit RO
Test..." );
System.Console.ReadLine();
}
}
}
and the client code:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace remoting
{
class MainClass
{
public static void Main(string[] args)
{
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel( chan );
new Sender();
Console.WriteLine( "press any key to continue..." );
Console.ReadLine();
}
}
}
i have one more object - the Sender(). in here, i start the timer, and
each 2 seconds will event rise up and call the method, i will
communicate with the remote object with. so here it comes:
using System;
using System.Timers;
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace remoting
{
public class Sender
{
System.Timers.Timer timer;
public Sender()
{
this.timer = new System.Timers.Timer( 2 * 1000 );
this.timer.Elapsed += new ElapsedEventHandler( OnTimerEvent );
this.timer.Enabled = true;
}
public void OnTimerEvent( object sender, ElapsedEventArgs e )
{
Console.WriteLine( ">> timer is running now..." );
Test obj = (Test) Activator.GetObject(
typeof( Test ),
"tcp://localhost:11111/Test" );
if( obj.Equals( null ) )
Console.WriteLine( "some error" );
else
{
Console.WriteLine( ">> yes, i am here..." );
Console.WriteLine( obj.Hello() );
Console.WriteLine( ">>...but i still can't get here :-(" );
}
}
}
so - if i didn't make some mistake in copy'n'paste and small rewriteing,
after compilation and start the server and the client, everything is
looking good, but the problem is, i will not get the result from the
remote method Hello() and the code will not get to the last message:
>>...but i still can't get here :-("
when i tryed to compile this program in windows, the result was the same
- no remote call and no last message - so it's not the bug. then after
dialog with my colleague, i tryed to create a thread instead of timer,
and try to call the remote object method from the thread. so - after
some modification, i create a new method in sender and remove the lines
in constructor. the method is as follows:
public void InThread()
{
for( int i = 0; i < 10; i++ )
{
Test obj = (Test) Activator.GetObject(
typeof( Test ),
"tcp://localhost:11111/Test" );
Console.WriteLine( obj.ToString() );
if( obj.Equals( null ) )
Console.WriteLine( "some error" );
else
Console.WriteLine( obj.Hello() );
Thread.Sleep( 2 * 1000 );
}
}
nothing specially changed, but after running, the exception raised (also
in linux (mono) and also in windows (.net framework)):
Unhandled Exception: System.Runtime.Remoting.RemotingException: Cannot
cast from client type 'sender.Test, sender, Version=1.0.2593.26378,
Culture=neutral, PublicKeyToken=null' to server type 'remoting.Test'
(the exception sounds simillar in windows:
Unhandled Exception: System.Runtime.Remoting.RemotingException: Cannot
load type
sender.Test, ConsoleApplication2, Version=1.0.2592.32086,
Culture=neutral, Publ
icKeyToken=null.
)
so - if somebody of you know, what is the problem about, please let me
know. it will be very helpful for me.
thanks
mirek
--
e-mail: mirek at host.sk
jabber: mirek at jabbim.sk
homepage: http://www.intrak.sk/~binas
english:
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
slovak:
prosim, neposielajte mi prilohy vo formatoch .doc a .ppt (power point)
precitajte si http://www.fsf.org/philosophy/no-word-attachments.cs.html
More information about the Mono-list
mailing list