473,465 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Found a bug in Remoting / Serialization

I came across an interesting bug I thought I would throw out there. It
occurs when you are remoting a parameter that is of the same type of the
class that is being called for example the first line of the Copy routine
succeeds where the second fails:

class MyType() : MarshalByRefObject
{
private string name;

public MyType()
{
}

public Copy(MyType myType)
{
// succeeds
this.name = myType.Name;

// throws exception if the myType is a remoting proxy
this.name = myType.name;
}

public string Name
{
get
{
return name;
}
}
}

--
Howard Swope [howardsnewsATspitzincDOTcom]
Software Engineer
Spitz, Inc [http://www.spitzinc.com]
Nov 17 '05 #1
9 1265
It's not that the method has a 'MyType' parameter:

You cannot access fields of a remoted object. You have to add a set
accessor to the Name property and use the property, not the field, in
the Copy method.

Remoting, IMO, must be used very carefully. There are a lot of gotchas
which can occur.

Nov 17 '05 #2
Following works for me, what exception is thrown on you?

// rdomas.cs
using System;
using System.Reflection;
namespace Willys {
public class HelloWorldWorker : MarshalByRefObject
{
string s;
public string S
{
get { return s;}
}
public void SayHello(HelloWorldWorker w)
{
this.s = "Hello";
this.s = w.S;
this.s = w.s + " world";
}
}
}

// main.cs
....
public static void Main()
{
AppDomain newDomain = AppDomain.CreateDomain("Second AppDomain");
HelloWorldWorker remote =
(HelloWorldWorker)newDomain.CreateInstanceAndUnwra p("rdomas",
"Willys.HelloWorldWorker");
remote.SayHello(remote);
Console.WriteLine(remote.S);
}

Willy.

"Howard Swope" <howardsnewsATspitzincDOTcom> wrote in message
news:uU*************@TK2MSFTNGP12.phx.gbl...
I came across an interesting bug I thought I would throw out there. It
occurs when you are remoting a parameter that is of the same type of the
class that is being called for example the first line of the Copy routine
succeeds where the second fails:

class MyType() : MarshalByRefObject
{
private string name;

public MyType()
{
}

public Copy(MyType myType)
{
// succeeds
this.name = myType.Name;

// throws exception if the myType is a remoting proxy
this.name = myType.name;
}

public string Name
{
get
{
return name;
}
}
}

--
Howard Swope [howardsnewsATspitzincDOTcom]
Software Engineer
Spitz, Inc [http://www.spitzinc.com]

Nov 17 '05 #3
I don't see that in the documentation, but I'll take your word for it. I
wonder why this is so. Obviously the data is there because I can access it
through the property. I guess it is the way that the proxy is wrapping
things up that makes this difficult or is there some other reason that
having direct access to the fields is unwise?

<jn*********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
It's not that the method has a 'MyType' parameter:

You cannot access fields of a remoted object. You have to add a set
accessor to the Name property and use the property, not the field, in
the Copy method.

Remoting, IMO, must be used very carefully. There are a lot of gotchas
which can occur.

Nov 17 '05 #4
Well this is interesting. I can access the fields if I marshal by value.

"Howard Swope" <howardsnewsATspitzincDOTcom> wrote in message
news:eL**************@TK2MSFTNGP14.phx.gbl...
I don't see that in the documentation, but I'll take your word for it. I
wonder why this is so. Obviously the data is there because I can access it
through the property. I guess it is the way that the proxy is wrapping
things up that makes this difficult or is there some other reason that
having direct access to the fields is unwise?

<jn*********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
It's not that the method has a 'MyType' parameter:

You cannot access fields of a remoted object. You have to add a set
accessor to the Name property and use the property, not the field, in
the Copy method.

Remoting, IMO, must be used very carefully. There are a lot of gotchas
which can occur.


Nov 17 '05 #5
Please post the whole code, it works for me see my other reply.

Willy.

"Howard Swope" <howardsnewsATspitzincDOTcom> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Well this is interesting. I can access the fields if I marshal by value.

"Howard Swope" <howardsnewsATspitzincDOTcom> wrote in message
news:eL**************@TK2MSFTNGP14.phx.gbl...
I don't see that in the documentation, but I'll take your word for it. I
wonder why this is so. Obviously the data is there because I can access it
through the property. I guess it is the way that the proxy is wrapping
things up that makes this difficult or is there some other reason that
having direct access to the fields is unwise?

<jn*********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
It's not that the method has a 'MyType' parameter:

You cannot access fields of a remoted object. You have to add a set
accessor to the Name property and use the property, not the field, in
the Copy method.

Remoting, IMO, must be used very carefully. There are a lot of gotchas
which can occur.



Nov 17 '05 #6
Hi,
I have a doubt. myType is an instance of class MyType and name is a private
variable within MyType. How can myType.name work?? It has to throw an
exception coz name is private??
Excuse me if I sound absurd.

"Howard Swope" wrote:
I came across an interesting bug I thought I would throw out there. It
occurs when you are remoting a parameter that is of the same type of the
class that is being called for example the first line of the Copy routine
succeeds where the second fails:

class MyType() : MarshalByRefObject
{
private string name;

public MyType()
{
}

public Copy(MyType myType)
{
// succeeds
this.name = myType.Name;

// throws exception if the myType is a remoting proxy
this.name = myType.name;
}

public string Name
{
get
{
return name;
}
}
}

--
Howard Swope [howardsnewsATspitzincDOTcom]
Software Engineer
Spitz, Inc [http://www.spitzinc.com]

Nov 17 '05 #7
myType.Name is being called from within a method of MyType. So it should
work and it does from anything but a Remoting proxy. I have been told in
another post that you can't access any fields from Remoting proxy. I
actually swithed MyType over to be Marshal by Value and it is behaving
properly.

"Ravi" <Ra**@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
Hi,
I have a doubt. myType is an instance of class MyType and name is a
private
variable within MyType. How can myType.name work?? It has to throw an
exception coz name is private??
Excuse me if I sound absurd.

"Howard Swope" wrote:
I came across an interesting bug I thought I would throw out there. It
occurs when you are remoting a parameter that is of the same type of the
class that is being called for example the first line of the Copy routine
succeeds where the second fails:

class MyType() : MarshalByRefObject
{
private string name;

public MyType()
{
}

public Copy(MyType myType)
{
// succeeds
this.name = myType.Name;

// throws exception if the myType is a remoting proxy
this.name = myType.name;
}

public string Name
{
get
{
return name;
}
}
}

--
Howard Swope [howardsnewsATspitzincDOTcom]
Software Engineer
Spitz, Inc [http://www.spitzinc.com]

Nov 17 '05 #8
I have a sample code it didn't work for me.

remote object code:

public class Hello:MarshalByRefObject
{
private ProductInfo pf;

public ProductInfo Product
{
get {return pf; }
}

public Hello()
{
System.Console.WriteLine("Constructor");
}

public string PrintHello()
{
System.Console.WriteLine("PrintHello");
pf = new ProductInfo();
pf.ProductID = 1;
pf.ProductXML="<Test>Remoting</Test>";
}
}

[Serializable]
public class ProductInfo //: MarshalByRefObject
{
public Int32 ProductID;
public string ProductXML;
public ArrayList Arr;

public ProductInfo()
{
Arr = new ArrayList();
Arr.Add(new Arr1(1));
}

}//class

client code: [getting exception at 4th line ]
ProductInfo pf;
b1 = h.PrintHello();
pf = h.Product;
this.textBox1.Text = pf.ProductID.ToString();
any clue why getting error.

Nov 17 '05 #9
jn*********@gmail.com wrote:
You cannot access fields of a remoted object. You have to add a set
accessor to the Name property and use the property, not the field, in
the Copy method.


I am far from a remoting expert, but I do not believe this is right. I
read (somewhere) in the dox that remote fields are automatically
turned into properties on the proxy.

Naturally, now I can't find an example in any of my remoting code ....

--

www.midnightbeach.com
Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Skip | last post by:
Hi, I get the following exception thrown when I try to run my code: "An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll Additional...
15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
3
by: Steve | last post by:
I've been following a couple remoting tutorials on the web, they are all pretty much the same. I've got my different applications built(client, server and remote object (dll)) The client is...
2
by: Satish A | last post by:
Hi, I'm writing a n-tier ASP.NET application with BusinessLogic as Remoting Objects While passing custom business entity object byref to remoting object methods i'm getting following error ...
4
by: WinDev | last post by:
What does this exception message mean? Type System.DelegateSerializationHolder and the types derived from it (such as System.DelegateSerializationHolder) are not permitted to be deserialized at...
2
by: Jigar.Patel | last post by:
Hi, I have following enum definition. public enum OperationTypes { All = 1, New = 2, View = 4,
0
by: ShaneN | last post by:
I'm working on a remoting application where the client only references interfaces for all wellknown objects. I currently have an object, Request being exposed: Imports System.Runtime.Remoting...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.