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

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.
 
D

dotnet007

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...
 

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