如何将 .exe 作为 .NET 程序集加载? [英] How to load an .exe as a .NET assembly?

查看:25
本文介绍了如何将 .exe 作为 .NET 程序集加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用吗?:

Assembly.LoadFile

不确定这是不是这样做的方法?

Not sure if this is the way to do this?

但是当我尝试这种方法时,它会抛出一个 无法加载文件或程序集CustomControlLib" 或其依赖项之一.系统找不到指定的文件.

But when I try that approach, it throws a Could not load file or assembly "CustomControlLib" or one of its dependencies. The system cannot find the file specified.

有什么想法吗?

推荐答案

您需要确保将依赖项也加载到应用程序域中.如果它们没有自动定位,您可以订阅 AppDomain.AssemblyResolve 以便在需要时手动查找和加载程序集.

You will need to make sure that the dependencies are also loaded into the app domain. If they aren't located automatically, you can subscribe to AppDomain.AssemblyResolve in order to find and load assemblies manually if needs be.

例如:

private Assembly AssemblyEventHandler(object sender, ResolveEventArgs args)
{
    return locatedAssembly;
}

另外,我会考虑使用 Assembly.LoadFrom,特别是 阅读此内容后,nobugz 提出了强有力的断言,并链接到 一些阅读(都过时了,但大部分时间应该仍然可以承受.)

Also, I would consider using Assembly.LoadFrom, particularly after reading this which has a strong assertion by nobugz and links to some good reading (all dated but ought to still be withstanding for the most part.)

这篇关于如何将 .exe 作为 .NET 程序集加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆