[Mono-bugs] [Bug 61774][Nor] New - Remoting problem when marshalling derived interfaces

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 21 Jul 2004 10:34:27 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by xmonicthfepm@spammotel.com.

http://bugzilla.ximian.com/show_bug.cgi?id=61774

--- shadow/61774	2004-07-21 10:34:27.000000000 -0400
+++ shadow/61774.tmp.18610	2004-07-21 10:34:27.000000000 -0400
@@ -0,0 +1,176 @@
+Bug#: 61774
+Product: Mono: Class Libraries
+Version: unspecified
+OS: All
+OS Details: Windows XP Prof. & SuSE Linux 9.1
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: XMONICTHFEPM@spammotel.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Remoting problem when marshalling derived interfaces
+
+Description of Problem:
+
+When using RemotingServices.Marshal(..., ..., typeof(DerivedInterface)) and
+then remotely call a method which is declared in the base class/interface
+an exception is thrown.
+
+Steps to reproduce the problem:
+
+1. Put the following code in a file called IServer.cs:
+--------------------------------------------------------------------
+namespace RemotingTest
+{
+    public interface IServer
+    {
+        void DoRemoteCall();
+    }
+
+    public interface IExtendedServer : IServer
+    {
+        void DoExtendedRemoteCall();
+    }
+}
+--------------------------------------------------------------------
+
+2. Put the following code in a file called Server.cs:
+--------------------------------------------------------------------
+using System;
+using System.Runtime.Remoting;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Channels.Tcp;
+using RemotingTest;
+
+namespace RemotingTest
+{
+    class Server : MarshalByRefObject, IExtendedServer
+    {
+        [STAThread]
+        static void Main( string[] args )
+        {
+            TcpChannel chan = new TcpChannel( 12345 );
+            ChannelServices.RegisterChannel( chan );
+            Server server = new Server();
+            RemotingServices.Marshal( server, "Server.rem", typeof(
+IExtendedServer ) );
+            Console.WriteLine("Press [Enter] to exit...");
+            Console.ReadLine();
+        }
+
+        public void DoRemoteCall()
+        {
+            Console.WriteLine( "Client called DoRemoteCall()" );
+        }
+
+        public void DoExtendedRemoteCall()
+        {
+            Console.WriteLine( "Client called DoExtendedRemoteCall()" );
+        }
+    }
+}
+--------------------------------------------------------------------
+
+3. Put the following code in a file called Client.cs:
+--------------------------------------------------------------------
+using System;
+using System.Runtime.Remoting;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Channels.Tcp;
+
+namespace RemotingTest
+{
+    class Client
+    {
+        [STAThread]
+        static void Main(string[] args)
+        {
+            TcpChannel chan = new TcpChannel();
+            ChannelServices.RegisterChannel( chan );
+            IExtendedServer server = (IExtendedServer)RemotingServices.Connect(
+                typeof( IExtendedServer ),
+"tcp://localhost:12345/Server.rem" );
+
+            server.DoExtendedRemoteCall();
+            Console.WriteLine( "DoExtendedRemoteCall() successful." );
+            server.DoRemoteCall();
+            Console.WriteLine( "DoRemoteCall() successful." );
+        }
+    }
+}
+--------------------------------------------------------------------
+
+4. Then, compile everything:
+
+mcs -t:library IServer.cs
+mcs -r:System.Runtime.Remoting -r:IServer Server.cs
+mcs -r:System.Runtime.Remoting -r:IServer Client.cs
+
+5. Start the server (mono Server.exe) on one console, then start the client
+(mono Client.exe) on another console.
+
+
+Actual Results:
+
+The following happens on the client side:
+--------------------------------------------------------------------
+DoExtendedRemoteCall() successful.
+
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+
+Server stack trace:
+in <0x0001a> System.Runtime.Remoting.RemotingServices:IsOneWay
+(System.Reflection.MethodBase)
+in <0x000f7>
+System.Runtime.Remoting.Channels.ChannelServices:DispatchMessage
+(System.Runtime.Remoting.Channels.IServerChannelSinkStack,System.Runtime.Remoting.Messaging.IMessage,System.Runtime.Remoting.Messaging.IMessage&)
+in <0x00023>
+System.Runtime.Remoting.Channels.ServerDispatchSink:ProcessMessage
+(System.Runtime.Remoting.Channels.IServerChannelSinkStack,System.Runtime.Remoting.Messaging.IMessage,System.Runtime.Remoting.Channels.ITransportHeaders,System.IO.Stream,System.Runtime.Remoting.Messaging.IMessage&,System.Runtime.Remoting.Channels.ITransportHeaders&,System.IO.Stream&)
+in <0x00246>
+System.Runtime.Remoting.Channels.BinaryServerFormatterSink:ProcessMessage
+(System.Runtime.Remoting.Channels.IServerChannelSinkStack,System.Runtime.Remoting.Messaging.IMessage,System.Runtime.Remoting.Channels.ITransportHeaders,System.IO.Stream,System.Runtime.Remoting.Messaging.IMessage&,System.Runtime.Remoting.Channels.ITransportHeaders&,System.IO.Stream&)
+
+
+Exception rethrown at [0]:
+
+in <0x00601> System.Runtime.Remoting.Proxies.RealProxy:PrivateInvoke
+(System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging.IMessage,System.Exception&,object[]&)
+--------------------------------------------------------------------
+
+
+Expected Results:
+
+Output on the client side (like it is with MS .NET 1.1):
+--------------------------------------------------------------------
+DoExtendedRemoteCall() successful.
+DoRemoteCall() successful.
+--------------------------------------------------------------------
+
+How often does this happen? 
+
+Always.
+
+Additional Information:
+
+If you change the line
+    RemotingServices.Marshal( server, "Server.rem", typeof( IExtendedServer
+) );
+in Server.cs to
+    RemotingServices.Marshal( server, "Server.rem", typeof( Server ) );
+it works fine. But here the problem is that this type may not always be
+available, e.g. because it's in a different file and the Server assembly
+would not be referenced.
+
+Even for this problem there's a workaround:
+    RemotingServices.Marshal( server, "Server.rem", server.GetType() );
+
+The strange thing is that this would also work when server was of type
+IExtendedServer (and not of type Server, as in the example).