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

查看:169
本文介绍了如何加载一个.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 ,特别是<一个href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/3bdaf65c-520c-4a1a-a825-fc2ca2957bf3#58e799db-1ad0-4ae8-81df-bf4bb06cc43a"相对=nofollow>阅读本具有由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天全站免登陆