Bug 5590 - System.Delegate.Combine(): Intermittent "Incompatible Delegate Types" exceptions when adding event handlers
Summary: System.Delegate.Combine(): Intermittent "Incompatible Delegate Types" excepti...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.2.x
Hardware: PC Windows
: Low normal
Target Milestone: 4.12.0 (KitKat)
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2012-06-08 20:30 UTC by anthony taranto
Modified: 2014-01-14 03:22 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description anthony taranto 2012-06-08 20:30:43 UTC
Our deployed app, built with 4.2.2 generates 2-3 crash logs per day that always look like the following:

Exception: Incompatible Delegate Types.
 at System.Delegate.Combine (System.Delegate a, System.Delegate b) [0x00000] in <filename unknown>:0
 at Foo.Bar.MyClass.add_MyEvent (Foo.Bar.MyEventHandler value) [0x00000] in <filename unknown>:0

Similar exceptions can be thrown from anywhere that adding an event handler occurs. There seems to be no pattern of class type of handler type that specifically triggers this or is immune to this. Obviously, this code succeeds the vast majority of the time and fails seemingly at random.

The only pattern is that most of the codepaths that are throwing this exception occur right around application startup. However, that is also when most event handler addition occurs so it may not be connected to the problem.
Comment 1 Rodrigo Kumpera 2013-05-22 16:35:17 UTC
Hi Anthony, there have been a bunch of fixes in this area in the last few stable releases.

Did you encounter this bug since 4.6?
Comment 2 anthony taranto 2013-05-22 19:12:24 UTC
We are shipping w/ 4.6.x and haven't seen this recently. I'll close. Thanks!
Comment 3 Brett 2013-10-16 12:42:43 UTC
This bug should be reopened as it is not resolved.

I am seeing this occur with Xamarin.Android 4.8.1 when running on a Nexus 10 with Android 4.3. It is not intermittent, and happens frequently.

Relavent stacktrace: http://sprunge.us/XXeV
Comment 4 Rodrigo Kumpera 2013-10-16 13:04:10 UTC
Hi Brett,

Reopening it then. We updated that code over a year ago to include the types involved in the exception message. Could you paste them?
Comment 5 Brett 2013-10-16 13:40:28 UTC
From the interface definition:

event Action<Source, int, ContextMenuItemAction> SourceContextActionActivated;

And the signature of the handler that is added:

private void view_SourceContextActionActivated(Source source, int index, ContextMenuItemAction action)


Source is class and ContextMenuItemAction is an enum.

What's really frustrating/confusing is that this works *some* times, but not all.
Comment 6 Brett 2013-10-16 13:44:14 UTC
Doh, sorry, I misread your last comment:

http://sprunge.us/UgNN

That contains the types from the exception.
Comment 7 Rodrigo Kumpera 2013-10-16 14:03:53 UTC
The delegate been appended is Action<object, int, int, Track, object>, does it ring any bell?
Comment 8 Brett 2013-10-16 15:45:57 UTC
So there 2 places where we have Actions with that signature, well the signature has a generic:

Action<object, int, int, TModel, object>

One is an event on our BaseListAdapter class (called ItemActionActivated), and the other is an ivar in ListActivationListener. But neither of those instances would ever be added to the SourceContextActionActivated event on BaseContextMenuFragment.

Is there anything else I can do to help troubleshoot?
Comment 9 Rodrigo Kumpera 2013-10-17 14:14:46 UTC
It give some food for though. I'll spend some time here next week.
Comment 10 Rodrigo Kumpera 2013-11-12 16:07:56 UTC
Fixed, will be part of android 4.10.2.
Comment 11 Sadik Ali 2014-01-14 03:22:53 UTC
I have verified this issue following are the steps:

1. Created android project
2. Create a class for event and combine two events using System.Delegate.Combine() method.

Refer screen shot: http://www.screencast.com/t/Kky4TTXgf

Checked with:
Window 8
XS 4.2.3 (Build 35)
XA 4.10.2