MissingMethodException with MulticastDelegate

J

Jon Skeet [C# MVP]

I've got a very bizarre problem to debug.

I have an application with various threads, two of which are of
interest here:

1) The UI thread
2) A background thread talking to a server

The UI has a status indicator to show whether the connection is
working, etc.

The background thread's main class has an event saying when the state
has changed. The UI subscribes to that event with two different
delegates. One of these delegates uses Control.Invoke to change the UI
itself - there's no nastiness like changing the UI from a different
thread, as far as I can see.

Now, most of the time, it all works fine, and I can step through both
delegates. When the connection has failed, however, invoking the
multicast delegate (which contains the two other delegates) invokes the
first delegate (which I can step through) but then throws a
MissingMethodException.

It has nothing to do with what the state has changed to - the same
value works fine if there hasn't been a connection failure.

Removing either of the delegates makes it work (as in not fall over).

I'm at a loss... any ideas?
 
M

mchacher

I have the same problem.
Thank you for your help

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
B

Brian Smith [MSFT]

When you are seeing the MissingMethodException, are you invoking the
delegate from within a "catch" handler?

Brian
--------------------
From: Jon Skeet [C# MVP] <[email protected]>
Subject: MissingMethodException with MulticastDelegate
Date: Tue, 25 May 2004 14:44:00 +0100

I've got a very bizarre problem to debug.

I have an application with various threads, two of which are of
interest here:

1) The UI thread
2) A background thread talking to a server

The UI has a status indicator to show whether the connection is
working, etc.

The background thread's main class has an event saying when the state
has changed. The UI subscribes to that event with two different
delegates. One of these delegates uses Control.Invoke to change the UI
itself - there's no nastiness like changing the UI from a different
thread, as far as I can see.

Now, most of the time, it all works fine, and I can step through both
delegates. When the connection has failed, however, invoking the
multicast delegate (which contains the two other delegates) invokes the
first delegate (which I can step through) but then throws a
MissingMethodException.

It has nothing to do with what the state has changed to - the same
value works fine if there hasn't been a connection failure.

Removing either of the delegates makes it work (as in not fall over).

I'm at a loss... any ideas?

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jon Skeet [C# MVP]

Brian Smith said:
When you are seeing the MissingMethodException, are you invoking the
delegate from within a "catch" handler?

Yes, and (if I remember rightly - I've fixed it by only using one
delegate) I can catch the exception. It just shouldn't be happening in
the first place. Unfortunately it looks like it would be relatively
tricky to reproduce in a small example - if it happens again, I'll try
to work one up though.
 
B

Brian Smith [MSFT]

You are hitting a bug in .NETCF v1 on ARM-compatible devices. A multicast
delegate (one bound to more than one method) invoked from within a catch
handler will not work properly. Specifically, only one method will be
called and then a MissingMethodException will be erroneously raised. The
workaround you used would be fine. If you really needed to invoke multiple
methods, you could use a collection (such as an array) of single-cast
delegates and invoke each one separately.

We are working on a fix and it will be included in the next service pack
for .NETCF v1 (SP3). It does not have a release date yet.
This bug does not exist in any of the pre-release versions of .NETCF v2.

I'm sorry for any inconvenience this may cause you.
Brian

--------------------
From: Jon Skeet [C# MVP] <[email protected]>
Subject: RE: MissingMethodException with MulticastDelegate
Date: Tue, 1 Jun 2004 20:18:45 +0100

Brian Smith said:
When you are seeing the MissingMethodException, are you invoking the
delegate from within a "catch" handler?

Yes, and (if I remember rightly - I've fixed it by only using one
delegate) I can catch the exception. It just shouldn't be happening in
the first place. Unfortunately it looks like it would be relatively
tricky to reproduce in a small example - if it happens again, I'll try
to work one up though.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jon Skeet [C# MVP]

Brian Smith said:
You are hitting a bug in .NETCF v1 on ARM-compatible devices. A multicast
delegate (one bound to more than one method) invoked from within a catch
handler will not work properly. Specifically, only one method will be
called and then a MissingMethodException will be erroneously raised. The
workaround you used would be fine. If you really needed to invoke multiple
methods, you could use a collection (such as an array) of single-cast
delegates and invoke each one separately.

We are working on a fix and it will be included in the next service pack
for .NETCF v1 (SP3). It does not have a release date yet.
This bug does not exist in any of the pre-release versions of .NETCF v2.

I'm sorry for any inconvenience this may cause you.

No problem - I'm glad it's a known bug. Thanks for the info - it's good
to hear there's an SP3 on the way, too.
 
A

Antao Almada

Thanks for clarifying this out. This exception was driving me crazy...
;-)

I found a workaround for this problem. Instead of raising the event
directly, I'm getting the invocation list for the event and calling each
delegate myself...

Here is an example for an event NetworkError:

#if NETCF
// HACK: there is a bug in CF that does not allow
// the raise of events inside a try/catch block
System.Delegate[] dels =
this.NetworkError.GetInvocationList();
for(int i = dels.Length - 1; i >= 0; --i)
{
NetworkErrorEventHandler del =
(NetworkErrorEventHandler)dels;
if(del != null)
del(this, new NetworkErrorEventArgs(this, ex));
}
#else
this.NetworkError(this,
new NetworkErrorEventArgs(this, ex));
#endif


Antao
____________________________
Antao Almada
http://www.ydreams.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top