Calling InvokeMember from transparent proxy

U

Ulrich Proeller

Hi all,

I'm trying to call methods of a remote server using
reflection but
always get a MissingMethodException, saying that the
requested method
cannot be found.

In detail:
I have a server Svr which extends the interface ISvr. Svr
and ISvr are
implemented in different assemblies "Interface.dll"
and "Svr.dll".
I have a client which uses methods of Svr in two different
ways:
a) Directly:
Svr.Foo();
b) Via Reflection:
Svr.GetType().InvokeMember("Foo",
BindingFlags.Public |

BindingFlags.Instance |

BindingFlags.InvokeMethod,
null, Svr, null);

There are 2 scenarios:
1. Directly, NON-Remoting:
The client has a direct reference to "Svr.dll". Both calls
work
perfectly.

2. Remoting, local machine, TCP channel:
The client creates a transparent proxy of ISvr using the
RemotingHelper class of Ingo Rammer:
ISvr svr = (ISvr)RemotingHelper.GetObject(typeof(ISvr));
In this case, direct calls to the server work fine, but
the calls
using InvokeMember throw a MissingMethodException.

After two days of research, I'm at a loss. Has anyone out
there an
idea?

Thanks in advance

Uli Proeller
prosa GmbH, Germany
 
J

Jeffrey Tan[MSFT]

Hi ULrich,

Thank you for posting in this group.
If you use invoke method instead of invokemember method, does the
exception still throw?

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Ulrich Proeller" <[email protected]>
| Sender: "Ulrich Proeller" <[email protected]>
| Subject: Calling InvokeMember from transparent proxy
| Date: Fri, 26 Sep 2003 03:20:42 -0700
| Lines: 51
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOEF9bgDUGhOMAmSzecs4MXBGmu2Q==
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:54796
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| Hi all,
|
| I'm trying to call methods of a remote server using
| reflection but
| always get a MissingMethodException, saying that the
| requested method
| cannot be found.
|
| In detail:
| I have a server Svr which extends the interface ISvr. Svr
| and ISvr are
| implemented in different assemblies "Interface.dll"
| and "Svr.dll".
| I have a client which uses methods of Svr in two different
| ways:
| a) Directly:
| Svr.Foo();
| b) Via Reflection:
| Svr.GetType().InvokeMember("Foo",
| BindingFlags.Public |
|
| BindingFlags.Instance |
|
| BindingFlags.InvokeMethod,
| null, Svr, null);
|
| There are 2 scenarios:
| 1. Directly, NON-Remoting:
| The client has a direct reference to "Svr.dll". Both calls
| work
| perfectly.
|
| 2. Remoting, local machine, TCP channel:
| The client creates a transparent proxy of ISvr using the
| RemotingHelper class of Ingo Rammer:
| ISvr svr = (ISvr)RemotingHelper.GetObject(typeof(ISvr));
| In this case, direct calls to the server work fine, but
| the calls
| using InvokeMember throw a MissingMethodException.
|
| After two days of research, I'm at a loss. Has anyone out
| there an
| idea?
|
| Thanks in advance
|
| Uli Proeller
| prosa GmbH, Germany
|
|
|
|
 
U

Ulrich Proeller

Hi Jeffrey,

neither my transparent proxy class nor the corresponding
interface has a Invoke method. So, I don't know what you
mean?

But meanwhile, I have additional info. My construction is
as follows:

public interface I1 : I2
{
...
}
public interface I2
{
void foo();
}

when calling
typeof(I1).InvokeMember("foo", ...);
I get a MissingMethodException,
but when I call
typeof(I2).InvokeMember("foo", ...);
everything goes fine.
Is this a intended behaviour?

Best Regards
Ulrich Proeller
prosa GmbH
 
J

Jeffrey Tan[MSFT]

Hi UIrich,

I mean that you can try to use Reflection to get the MethodInfo array of
Svr, then
you can invoke foo method by MethodInfo.Invoke method.
You can try to find if this generate exception.

For your sample, I think the exception is expected.
If you create an instance and get the I1 interface, the direct invoke of
I1.Foo will
work well.
But the reflection way of doing this by invokemember will fail, the
reflection
is based on assembly's metedata, and if you check the metadata by
ILdasm.exe you will see that
there is no foo method in I1 interface, so it can not use reflection to
invoke I1's foo method.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Ulrich Proeller" <[email protected]>
| Sender: "Ulrich Proeller" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: Calling InvokeMember from transparent proxy
| Date: Mon, 29 Sep 2003 04:36:24 -0700
| Lines: 29
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOGfelq017g/DGZTFeWNhvk0Czh+A==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:54954
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| Hi Jeffrey,
|
| neither my transparent proxy class nor the corresponding
| interface has a Invoke method. So, I don't know what you
| mean?
|
| But meanwhile, I have additional info. My construction is
| as follows:
|
| public interface I1 : I2
| {
| ...
| }
| public interface I2
| {
| void foo();
| }
|
| when calling
| typeof(I1).InvokeMember("foo", ...);
| I get a MissingMethodException,
| but when I call
| typeof(I2).InvokeMember("foo", ...);
| everything goes fine.
| Is this a intended behaviour?
|
| Best Regards
| Ulrich Proeller
| prosa GmbH
|
 
Top