[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

cast succeeds on proxied object when it shouldn't

frank.colbert

8/13/2004 10:10:00 PM

I have a curious case where the "is" keyword seems to be incorrectly
succeeding on a remote object (TransparentProxy). I am wondering if
this is a known issue? Here is my scenario:

I create a SAO (singleton) via the Activator object. This is working
correctly as I am able to cast the object to an implemented interface
and execute methods on it.

I then call a method where I pass this in as object. Within this
method I check for 2 additional interfaces using the is keyword. My
remote object implements one of these interfaces and not the other.
The problem is that when I check the first interface which I DO NOT
imlement, it incorrectly passes the "is" check. I then get an
exception that the Type doesn't implement the method which is of
course true. If I force the debugger to execute the other "correct"
code path all works fine.

I was able to get around this by getting the proxied type and using
reflection to get at the implemented interface names and checking
against the 2 interfaces in this way.

Why would my casts unexpectedly succeed?

Thanks in Advance,

Franklin Colbert
8 Answers

Ken Kolda

8/13/2004 10:19:00 PM

0

Frank --

There was a long discussion about this a few weeks ago. Check out this
thread:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=ORy8Gp3ZEHA.2216%40TK2MSFTNGP10.phx.gbl&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3DORy8Gp3ZEHA.2216%2540TK2MSFTNGP...

Ken


"Frank Colbert" <frank.colbert@timberline.com> wrote in message
news:d963d0b5.0408131409.7452645@posting.google.com...
> I have a curious case where the "is" keyword seems to be incorrectly
> succeeding on a remote object (TransparentProxy). I am wondering if
> this is a known issue? Here is my scenario:
>
> I create a SAO (singleton) via the Activator object. This is working
> correctly as I am able to cast the object to an implemented interface
> and execute methods on it.
>
> I then call a method where I pass this in as object. Within this
> method I check for 2 additional interfaces using the is keyword. My
> remote object implements one of these interfaces and not the other.
> The problem is that when I check the first interface which I DO NOT
> imlement, it incorrectly passes the "is" check. I then get an
> exception that the Type doesn't implement the method which is of
> course true. If I force the debugger to execute the other "correct"
> code path all works fine.
>
> I was able to get around this by getting the proxied type and using
> reflection to get at the implemented interface names and checking
> against the 2 interfaces in this way.
>
> Why would my casts unexpectedly succeed?
>
> Thanks in Advance,
>
> Franklin Colbert


unknown

8/13/2004 11:44:00 PM

0

Ken,

Thanks for the thread reference. I hadn't seen this - very interesting
though pretty disturbing. It seems that this is a fairly serious bug in
the remoting infrastructure. (I wonder what MS has to say about
this....)

Here is some starting code to address the issue:

if (RemotingServices.IsTransparentProxy(obj)) {
RealProxy proxy = RemotingServices.GetRealProxy(obj);
Type ptype = proxy.GetProxiedType();
Type[] ifaces = ptype.GetInterfaces();
foreach (Type iface in ifaces) {
if (iface.Name == "ISomeIface1") {
ISomeIface1 iface1 = (ISomeIface1) obj;
iface1.DoThis();
break;
}
else if (iface.Name == "ISomeIface2") {
ISomeIface2 iface2 = (ISomeIface2) obj;
iface2.DoThat();
break;
}
}


This seems gimpy as hell, but whatya gonna do.....

*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

Ken Kolda

8/14/2004 12:22:00 AM

0

Although I can't say I've tried this, couldn't you just call

Type t = obj.GetType();

directly without getting the proxy first? Of course, the drawback either way
is that this requires you have the assembly with the server's class
implementation accessible on the client.

Ken


"clutchngrab" <nospam@nospam.com> wrote in message
news:e8nZ09YgEHA.3728@TK2MSFTNGP10.phx.gbl...
> Ken,
>
> Thanks for the thread reference. I hadn't seen this - very interesting
> though pretty disturbing. It seems that this is a fairly serious bug in
> the remoting infrastructure. (I wonder what MS has to say about
> this....)
>
> Here is some starting code to address the issue:
>
> if (RemotingServices.IsTransparentProxy(obj)) {
> RealProxy proxy = RemotingServices.GetRealProxy(obj);
> Type ptype = proxy.GetProxiedType();
> Type[] ifaces = ptype.GetInterfaces();
> foreach (Type iface in ifaces) {
> if (iface.Name == "ISomeIface1") {
> ISomeIface1 iface1 = (ISomeIface1) obj;
> iface1.DoThis();
> break;
> }
> else if (iface.Name == "ISomeIface2") {
> ISomeIface2 iface2 = (ISomeIface2) obj;
> iface2.DoThat();
> break;
> }
> }
>
>
> This seems gimpy as hell, but whatya gonna do.....
>
> *** Sent via Developersdex http://www.develop... ***
> Don't just participate in USENET...get rewarded for it!


unknown

8/14/2004 12:54:00 AM

0


Yup. That works. Thanks for the tip!


*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

Lichsu Vietnam

9/3/2010 10:44:00 PM

0

President Nguyen Van Thieu, Quang was formerly a power in Saigon He
abused... ...to panicky South Viet- namese refugees trying to flee
ahead of the Communists One refugee has... ...Williamson of 18
Bromletgh Ave London On tario Canada Stanley G Robins of East Mam
St... ...Travers Williamson 18 Bromleigh Avenue London Ontario Canada
Robins East Main Street Salisbury, Md 21801 Personal... ...a faceless
refugee But other refugees recognized him and threatened retaliation
Less than two weeks after...

Lichsu Vietnam

9/3/2010 10:55:00 PM

0

U.S. involvement in Vietnam LONDON (AP) Nguyen Van Thieu, former
president of what once was... ...quoted Friday in a rare interview as
saying U.S. troops were more trouble than help in... ...been living
reclusively in a London suburb since shortly after the fall of Saigon
in 1975... ....really mean this." the magazine interview continued.
"Without the American presence we could have beaten the...

=====No kidding :)

Lichsu Vietnam

9/3/2010 11:01:00 PM

0

Americans of all the figures of that beleaguered country. He was a
marshal of the South Vietnamese air force, for a time the nation's
premier, and then vice president. He tried to run for the presidency
in 1971 but was squeezed out by Lt. Gen. Nguyen Van Thieu. Then he
became a farmer and disappeared from the political stage for four
years. At his political peak, Ky bore the nickname "Captain Midnight"
because of his flashy a black flight suit

==== Ky ma('m to^m is "Captain Midnight" :)))))))))))

Lichsu Vietnam

9/3/2010 11:12:00 PM

0

Dda^'y, tha(`ng Quack Thien ddo.c ro^`i ma` a(n ca('p tie^'m info tu*.
nhie^n dde^? vie^'t sa'ch ba'n