0

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

mb345345
  • 165
  • 6
  • 1
    Have you checked your binding redirects in your config file? – ams4fy Aug 03 '16 at 08:26
  • http://stackoverflow.com/a/2279368/2613020 this can help you – Sarvesh Mishra Aug 03 '16 at 08:36
  • Use Fuslogvw.exe to troubleshoot assembly resolution problems. Log all binds. Improve your question by showing the trace you get. Reflector does not make these kind of "mistakes" btw, it is not subject to CLR binding policy. So high odds that the assemblies in the GAC are just not the ones you hope they are. – Hans Passant Aug 03 '16 at 08:52

1 Answers1

0

You can fully qualify the type like so

var type = Type.GetType("ConsoleApplication2.Albert, ConsoleApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
Activator.CreateInstance(type);
Peter Morris
  • 20,174
  • 9
  • 81
  • 146