[Mono-bugs] [Bug 47817][Nor] New - RealProxy implementing IRemotingTypeInfo.CanCastTo is ignored for casts

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 22 Aug 2003 04:34:33 -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 vladimir@pobox.com.

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

--- shadow/47817	2003-08-22 04:34:33.000000000 -0400
+++ shadow/47817.tmp.14625	2003-08-22 04:34:33.000000000 -0400
@@ -0,0 +1,89 @@
+Bug#: 47817
+Product: Mono/Runtime
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: vladimir@pobox.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: RealProxy implementing IRemotingTypeInfo.CanCastTo is ignored for casts
+
+the following sample program:
+
+---- bug5.cs ----
+
+using System;
+using System.Runtime.Remoting;
+using System.Runtime.Remoting.Messaging;
+using System.Runtime.Remoting.Proxies;
+ 
+public abstract class TestClass : MarshalByRefObject {
+  public abstract void Foo ();
+}
+ 
+public abstract class Derived : TestClass {
+}
+ 
+public class TestProxy : RealProxy, IRemotingTypeInfo {
+  public TestProxy (Type baseType) : base (baseType)
+  {
+  }
+ 
+  public override IMessage Invoke (IMessage msg) {
+    Console.WriteLine ("Invoke: ");
+    Console.WriteLine (msg.GetType());
+ 
+    IMethodCallMessage mcall = msg as IMethodCallMessage;
+ 
+    IMethodReturnMessage ret = new ReturnMessage (null, null, 0,
+                                                  mcall.LogicalCallContext,
+                                                  mcall);
+    Console.WriteLine ("Finish");
+    return ret;
+  }
+ 
+  string tn;
+  string IRemotingTypeInfo.TypeName {
+    get { return tn; }
+    set { tn = value; }
+  }
+ 
+  bool IRemotingTypeInfo.CanCastTo (System.Type target, object o) {
+    Console.WriteLine ("CanCastTo " + target);
+    return true;
+  }
+}
+ 
+public class Driver {
+  public delegate void FooDelegate();
+ 
+  public static void Main () {
+    TestProxy tp = new TestProxy (typeof(TestClass));
+    TestClass tc = (TestClass) tp.GetTransparentProxy();
+ 
+    Derived d = (Derived) tc;
+  }
+}
+
+---- end ----
+
+Generates:
+Unhandled Exception: System.InvalidCastException: Cannot cast from source
+type to destination type
+in <0x000a7> 00 .Driver:Main ()
+
+under mcs/mono post-0.26 cvs.
+
+Under the MS CLR, v1.1 it correctly prints "CanCastTo Derived" indicating
+that CanCastTo was called.
+
+(Note that the IL itself is correct -- a mcs-compiled test5.exe verifies
+and executes under the MS CLR.)