mercredi 3 août 2016

c# Activator.CreateInstanceFrom with dependencies picks wrong version from GAC

Old code, eg. Albert.dll is being late bound (with Activator.CreateInstanceFrom) to instantiate the Albert class. It has a dependency of Barry, which is held in the GAC, with various versions (eg. 1-6). Albert references version 3 of Barry, but when instantiated, tries to use 6 (latest) and succeeds. But when the code tries to cast the Albert class as a Barry, it fails with an "unable to cast" exception. I can't add version hints, because the version required is dynamic. Reflector makes the same mistake as .net, references v3, then instantiates with v6.

Seems to work ok on the old server (03, .net1), but now fails on new (2012, .net 4.6.1).





Aucun commentaire:

Enregistrer un commentaire