This message was discovered on microsoft.public.dotnet.framework.remoting.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Julien Barbé |
Hi,
Does anyone know where is the problem ???
I receive a Unhandled Exception: System.InvalidCastException: Return argument has an invalid type. on the getA() function !
getA() is a function from object B and returns a new object A. object A has one property i that is a int = 1.
I try to to display property i of the A on the client. From the server, only object B is remotely available. From the client I call getA() from a objB I use "shared" interfaces between client and server.
Thanks, Julien.
//CLIENT CODE ***************** using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Remoting.Channels;
namespace Test { //SHARED INFO *********** public interface IA { int i {get;} } public interface IB { IA getA(); } //************************
class RemotingExampleClient { static void Main(string[] args) { ChannelServices.RegisterChannel(new TcpClientChannel()); IB objB =(IB)Activator.GetObject(typeof(IB),"tcp://localhost:9988/B"); Console.WriteLine("B created " + objB.ToString()); Console.WriteLine("objB.getA().i"+ objB.getA().i); } } }
//SERVER CODE ***************** using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Serialization;
namespace Test { public class EntryPoint { public static void Main(string[] args) { TcpServerChannel channel = new TcpServerChannel(9988); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType(typeof(B),"B", WellKnownObjectMode.SingleCall); System.Console.WriteLine("Press Any Key"); System.Console.ReadLine(); } }
//SHARED INFO *********** public interface IA { int i {get;} } public interface IB { IA getA(); } //************************
public class A : MarshalByRefObject, IA { private int i_i = 1; public int i { get {return this.i_i;} } }
public class B : MarshalByRefObject, IB {
public IA getA() { return new A(); } }
}
|
|
| |
| | |
| |
| Jon Z. (VIP) |
I'm having this same problem with my remoting app. I was able to make it work by doing away with the interfaces. Of course, this means you have to install the server DLL on every client. Yuk! Hopefully, somebody can tell us both how to make this work with interfaces.
Jon Z.
"Julien Barbé" wrote:
[Original message clipped]
|
|
| |
|
| |
| Ken Kolda |
The problem is that you haven't really "shared" the interfaces. It is not sufficient to define the same interface in both the client and server assemblies. The assembly in which an interface lives is considered part of its identity. Thus, when your client calls getA(), it is receiving an object which implements "IA, Server", and the client is attempting to cast it to "IA, Client". Since the class doesn't implement this interface, you get the exception.
To solve this, put your shared interfaces in a seperate assembly and reference that assembly from both client and server. Your Server assembly would still hold the definition for class A, but IA would now be in a separate assembly.
Ken
"Julien Barbé" <Click here to reveal e-mail address> wrote in message news:41361234$0$3552$Click here to reveal e-mail address... [Original message clipped]
|
|
| |
| | |
|
|
|
|
|