Closed tamlin-mike closed 6 years ago
Is this from some code found in the wild or is it a constructed example? Two points that make me wonder:
1) The IL does not contain any field declaration. I find it baffling that ilasm does not issue any warning at all.
2) The event type is EvType, which is declared as plain class. Because it is not deriving from System.Delegate
in any way, the decompiler correctly adds casts to System.Delegate, when passing evType2 and value to Delegate.Combine/Delegate.Remove...
This is not a bug. If this is in the real code, the IL is horribly broken and cannot be translated to a C# auto event. It would not compile because of CS0066: event must be of a delegate type
.
Could you please send me the original assembly to verify this?
I have adjusted your test case and added a fix to the mcs pattern for the missing type arguments in the output of ExpressionBuilder. Can you please confirm, whether this fixes the issue?
It's from code found in the wild, though I obviously messed it up little when trying to anonymize it. The actual delegate (still anonymized) is
.class public auto ansi sealed EvType extends [mscorlib]System.MulticastDelegate
{
// Methods not included. Just the run of the mill ctor + {Begin|End}?Invoke
}
OwningClass indeed also have
.field private class EvType EvName
Sorry about that - though in retrospect, I am also a bit surprised ilasm didn't complain.
I have verified that it now works with HEAD, but I'll still send you the assembly for completeness.
The following IL can be assembled using
ilasm
.The problem seems to be that in
Pattern.DoMatchCollection
thecur2
variable doesn't have a trailing type Role after its reference to CompareExchange, but the patternautomaticEventPatternV4MCS
expects it.Additionally, when trying to decompile this, ILSpy hits an assert about the Threading namespace being inserted but is not part of referenced, which I guess in a sense is correct since it probably expected the event patternmatcher to have handled this and therefore not pull in
Threading
manually.