开发者

Load depending Dlls dynamically from a dll using appdomain - ResolveEventHandler

HI all

I have a dll c#.net project and it refers some other sub dlls. The exe application which uses my main dll is in another folder and it dynamically load the main dll using "Assembly.LoadFile". My problem is since other sub dlls are in the folder of the main dll exists, exe couldn't load the main dll.(because the dependencies of the main dll is not available in the exe path.) but when I copy the sub dlls into exe folder and dynamically load the main dll it works fine. I want to keep all dlls in one folder and dynamically load main dll. How can I resolve this problem? (All are C#/.net2.0 Projects)

Will Appdomain-ResolveEventHandler Delegate help m开发者_开发知识库e to solve this?

Thanks Regards, Robo.


Yes, this is exactly what you need to solve your assembly loading problems. If you subscribe to the AppDomain.CurrentDomain.AssemblyResolve event, you will be called when the CLR tries to bind to an assembly and fails. The event passes you a ResolveEventArgs parameter that contain the name of the failed assembly and then you can manually call Assembly.LoadFrom with the path of your choice and return that assembly instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜