在AppDomain中加载程序集字节

时间:2017-03-27 19:23:25

标签: c# .net .net-assembly appdomain

我正在尝试将程序集加载到appdomain中。

  

无法加载程序集“Test.dll”。 System.IO.FileNotFoundException:无法加载文件或程序集'Test,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'或其依赖项之一。系统找不到指定的文件。

我正在使用字节来加载程序集而不是路径。 我查看了一个示例,该示例还在下面指定了一个Proxy类。

AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = System.Environment.CurrentDirectory;
Evidence adevidence = AppDomain.CurrentDomain.Evidence;
dmname = AppDomain.CreateDomain("test", adevidence, domaininfo);

装载:

Assembly = Store.dmname.Load(bytes);

使用Proxy类:

        internal class Proxy : MarshalByRefObject
        {
            internal Assembly GetAssembly(byte[] assemblyPath)
            {
                try
                {
                    return Assembly.Load(assemblyPath);
                }
                catch (Exception)
                {
                    return null;
                    // throw new InvalidOperationException(ex);
                }
            }
        }

Type type = typeof(Store.Proxy);
var value = (Store.Proxy)Store.dmname.CreateInstanceAndUnwrap(
                        type.Assembly.FullName,
                        type.FullName);

Assembly = value.GetAssembly(bytes);

我尝试了两种方式,最终我也是这样。有没有办法使用byte []将程序集加载到appdomain?我不想保存它。

0 个答案:

没有答案
相关问题