开发者

Dll redirection not working in C# to deal with dll-hell with dot local file (appname.exe.local)

I used to successfully test multiple versions of code without having to worry about dll dependency by creat开发者_如何学Pythoning a zero byte application_name.exe.local file in the folder containing the new version of the application. However, we have to move to C# and this technique is no longer working. Is there something else needed (other than .local file) to ensure C# dlls look at the current folder first and then go chase other dlls in the application’s default location?


You can always hook into the AppDomain.AssemblyResolve event as Tejs suggests:

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

...

public static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    Assembly AlreadyLoaded=AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName == args.Name);
    if(AlreadyLoaded==null)
        return Assembly.LoadFile(Path to corresponding DLL);
}

It's not perfect (may need to load the DLLs in whatever directory you want to search in and then replace the Assembly.LoadFile line with a search of those DLLs), but you should be able to modify that to work. Hopefully anyway.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜