AssemblyResolve: Missleading multicastdelegate, unusable in real scenarios by design?

  • Thread starter Thread starter dotnet007
  • Start date Start date
D

dotnet007

Hi to All,

To jump into the deep instantly: Multicast event must not have return
value... by definition
Well, AssemblyResolve event has...

It returns the resolved assembly. But what if when you subscribe more than
one handler _independently_
to listen this event? That is why "Multicast event must not have return
value..."

Unfortunatelly localization (satellite assemblys) rely on AssemblyResolve.
So if you use localization, you can not attach your custom event handler ot
AssemblyResolve, because there is no way (by design of AssemblyResolve
event signature) to cooperate with each other.

As a last chance you think you go back 40 years to interrupt vector
chaining, and before you subscribe, you save the existing handler, and call
it in your new handler... But this is bad idea in three ways:

1) First of all it is impossible to get the existing handlers, because it is
an event, and not a "delegate type property" so we have a compiler
restriction (This is a good thing. the design error not in here, but the
event signature)
2) There is no guarantee that other subscribers will do the same if their
subscription is happen later in time... (after yours)

So the pretty += operator what are we using to subscribe is really a
randomly overriding = operator in this case.

What would be a good design?

No return value, and an bool Handled property in the ResolveEventArgs, and
the ResolvedAssembly property in ResolveEventArgs shoud do the work.

Missed I something?

thx for answers
 
It actually depends on whether the subscribers to the event are well
behaved (in an undocumented way, unfortunately), meaning they should
return null if they couldn't resolve the assembly.

The current implementation settles with the first non null result; your
proposed design would work just the same (until the first handled call),
though it does look more consistent.
 
Hi, thx for answer.

I suppose this means that Fireer (caller) of this event can not simple fire
the multicastdelegate, but must explicit write a (foreach) cycle on
delegate's invocationlist, and call separately each one, and break the cycle
if one of the called handlers returns not null...

No comment...
 
Back
Top