Details on how to handle AppDomain.AssemblyResolve event properly upon updating the needed assembly

16 Views Asked by At

I have an application which relies in outside assemblies to execute scripts. Some of the scripts assemblies depend on each other and since they are all editable by the user we are expected to be able to update and reload them properly.

These assemblies are loaded into memory in a class called script engine and every assembly that is a dependency is too. Originally, whenever invoking a method in these loaded assemblies it'd fail to find the dependency we had provided so that's why I started using the assembly resolve event.

I added an event handler on our CurrentDomain.AssemblyResolve event to check if the requested assembly was one of the dependencies we had loaded into memory. This way we could return it if this was the case.

The problem now comes when we want to update that dependency. The assembly resolve event only gets fired once per assembly which means that if we ever update said dependency the event won't fire again and the engine will keep using the old assembly.

I'm hoping to understand more of how this event gets trigerred and how can we tamper with the loaded assemblies in the domain to make sure the event gets triggered as many times as we need it too.

Some different aproaches have come to my mind to circunvent this problem by manipulating properties of the assembly, such as changing it's name systematically or it's version to make sure the newest version always trigerrs the event.

This could potentially solvent the issue but I'd much rather get an idea of the conditions that trigger this event and how to control it efficiently.

0

There are 0 best solutions below