How to load an .exe as a .NET assembly?

后端 未结 4 411
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 16:10

Can I just use?:

Assembly.LoadFile

Not sure if this is the way to do this?

But when I try that approach, it throws a Could not lo

4条回答
  •  时光取名叫无心
    2021-02-02 16:54

    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.

    For example:

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

    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.)

提交回复
热议问题