0

I asked a question here and apparently the problem is where I can load an assembly using Reflection's Assembly.LoadFile or Assembly.LoadFrom, and get the type inside that assembly, the assembly is still not accessible in the whole application. So when WPF tries to resolve a type, it doesn't find that type because it doesn't find the assembly.

My question is, can I reference an assembly at runtime, so that it will be resolvable by WPF?

Community
  • 1
  • 1
Louis Rhys
  • 34,517
  • 56
  • 153
  • 221
  • possible duplicate of [How to add types from external assembly to toolbox control? (WPF)](http://stackoverflow.com/questions/4594968/how-to-add-types-from-external-assembly-to-toolbox-control-wpf) – Hans Passant Jan 05 '11 at 07:03
  • You haven't provided any new info in this duplicate question. – Hans Passant Jan 05 '11 at 07:03
  • I'm not posting a duplicate question. I am making the question more general so it would also apply in different situation. – Louis Rhys Jan 05 '11 at 07:07

1 Answers1

0

A solution that works for me is handling the CurrentDomain.AssemblyResolve event

AppDomain.CurrentDomain.AssemblyResolve += 
    new ResolveEventHandler(OnAssemblyResolveFailure);

Assembly OnAssemblyResolveFailure(object sender, ResolveEventArgs args)
    {
        AssemblyName name = new AssemblyName(args.Name);
        Assembly assembly = .. //some logic here to load the assembly from assembly name
        return assembly;
    }

This way if the application cannot resolve an assembly name it will call your handler to find it

Louis Rhys
  • 34,517
  • 56
  • 153
  • 221