开发者

How to make an external assembly available at runtime?

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 w开发者_如何学编程hen 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜