当前位置: 首页>>代码示例>>C#>>正文


C# AppDomain.CreateInstanceFromAndUnwrap方法代码示例

本文整理汇总了C#中System.AppDomain.CreateInstanceFromAndUnwrap方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.CreateInstanceFromAndUnwrap方法的具体用法?C# AppDomain.CreateInstanceFromAndUnwrap怎么用?C# AppDomain.CreateInstanceFromAndUnwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.AppDomain的用法示例。


在下文中一共展示了AppDomain.CreateInstanceFromAndUnwrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        static void Load()
        {
            if (AppDomain.CurrentDomain.FriendlyName != "OnlineVideosSiteUtilDlls")
            {
                if (_useSeperateDomain)
                {
                    _domain = AppDomain.CreateDomain("OnlineVideosSiteUtilDlls", null, null, null, true);

                    // we need to subscribe to AssemblyResolve on the MP2 AppDomain because OnlineVideos.dll is loaded in the LoadFrom Context
                    // and when unwrapping transparent proxy from our AppDomain, resolving types will fail because it looks only in the default Load context
                    // we simply help .Net by returning the already loaded assembly from the LoadFrom context
                    AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;

                    _pluginLoader = (PluginLoader)_domain.CreateInstanceFromAndUnwrap(
                      Assembly.GetExecutingAssembly().Location,
                      typeof(PluginLoader).FullName);

                    AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolve;

                    _domain.SetData(typeof(PluginLoader).FullName, _pluginLoader);
                }
                else
                {
                    _domain = AppDomain.CurrentDomain;
                    _pluginLoader = new PluginLoader();
                }
            }
            else
            {
                _domain = AppDomain.CurrentDomain;
                _pluginLoader = (PluginLoader)AppDomain.CurrentDomain.GetData(typeof(PluginLoader).FullName);
            }
        }
开发者ID:offbyoneBB,项目名称:mp-onlinevideos2,代码行数:33,代码来源:OnlineVideosAppDomain.cs

示例2: ProcessAssembly

        public void ProcessAssembly(string filename)
        {
            FileInfo fileInfo = new FileInfo(filename);
            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationBase = fileInfo.DirectoryName;
            setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
            setup.ApplicationName = "Loader";
            setup.ShadowCopyFiles = "true";

            try
            {
                appDomain = AppDomain.CreateDomain("Loading Domain", null, setup);
                AssemblyProcessor processor = (AssemblyProcessor)
                   appDomain.CreateInstanceFromAndUnwrap(
                   "TestAssembly.dll",
                   "TestAssembly.AssemblyProcessor");
                string name = fileInfo.Name.Replace(fileInfo.Extension, "");
                Console.WriteLine(name);
                processor.Load(name);
                processor.Process();
            }
            finally
            {
                if (appDomain != null)
                {
                    AppDomain.Unload(appDomain);
                    appDomain = null;
                }
            }
        }
开发者ID:felix-tien,项目名称:TechLab,代码行数:30,代码来源:AppDomainTest.cs

示例3: SetUp

		public void SetUp()
		{
			string path = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;

			_localDomain = AppDomain.CreateDomain("NewDomain");
			_localDomain.Load(typeof(DataAccessor).Assembly.GetName());
			_localTest = (DataAccessorBuilderTest)_localDomain.CreateInstanceFromAndUnwrap(path, GetType().FullName);
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:8,代码来源:DataAccessorBuilderTest.cs

示例4: InitDomain

        private void InitDomain(string name, AppDomainSetup setup)
        {
#if STATIC

#else
            _currDomain = AppDomain.CreateDomain(name, null, setup);
            var type = typeof(ScriptDomainContext);
            _context = (ScriptDomainContext)_currDomain.CreateInstanceFromAndUnwrap(type.Assembly.GetName().CodeBase, type.FullName);
#endif
        }
开发者ID:LeeWangyeol,项目名称:Scut,代码行数:10,代码来源:ScriptRuntimeDomain.cs

示例5: MathAssembly

		public MathAssembly(string expression, string variable)
		{
			var mathAssembly = new MathFuncAssemblyCecil();
			_fileName = "MathFuncLib" + "_" + GenerateRandomString(6) + ".dll";
			mathAssembly.CompileFuncAndDerivative(expression, variable, "", _fileName);
			_domain = AppDomain.CreateDomain("MathFuncDomain");
			_mathFuncObj = _domain.CreateInstanceFromAndUnwrap(_fileName, mathAssembly.NamespaceName + "." + mathAssembly.ClassName);
			var mathFuncObjType = _mathFuncObj.GetType();
			FuncMethodInfo = mathFuncObjType.GetMethod(mathAssembly.FuncName);
			FuncDerivativeMethodInfo = mathFuncObjType.GetMethod(mathAssembly.FuncDerivativeName);
		}
开发者ID:0xmono,项目名称:MathExpressions.NET,代码行数:11,代码来源:MathAssembly.cs

示例6: GetDomain

		RemoteSetupDomain GetDomain ()
		{
			lock (this) {
				if (useCount++ == 0) {
					AppDomain.CurrentDomain.AssemblyResolve += MonoAddinsAssemblyResolve;
					domain = AppDomain.CreateDomain ("SetupDomain", null, AppDomain.CurrentDomain.SetupInformation);
					var type = typeof(RemoteSetupDomain);
					remoteSetupDomain = (RemoteSetupDomain) domain.CreateInstanceFromAndUnwrap (type.Assembly.Location, type.FullName);
				}
				return remoteSetupDomain;
			}
		}
开发者ID:wanglehui,项目名称:mono-addins,代码行数:12,代码来源:SetupDomain.cs

示例7: CreateAssemblyLoader

 public static AssemblyLoader CreateAssemblyLoader(AppDomain appDomain) {
    try {
       var assemblyLoader = appDomain.CreateInstanceFromAndUnwrap(
          typeof(AssemblyLoader).Assembly.CodeBase,
          typeof(AssemblyLoader).FullName);
       return assemblyLoader as AssemblyLoader;
    }
    catch (Exception ex) {
       Debug.WriteLine(ex);
       return null;
    }
 }
开发者ID:ManfredLange,项目名称:csUnit,代码行数:12,代码来源:AssemblyLoader.cs

示例8: Create

        public ILoader Create()
        {
            AppDomainSetup adSetup = new AppDomainSetup();
            adSetup.ShadowCopyFiles = "true"; // not a boolean

            m_LoaderDomain = createAppDomainForLoader(adSetup);
            string dir = m_LoaderDomain.SetupInformation.ApplicationBase;

            string selfAssemblyName = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;

            ILoader loader = (ILoader) m_LoaderDomain.CreateInstanceFromAndUnwrap(selfAssemblyName, "Cider_x64.Loader");
            return loader;
        }
开发者ID:pziacek,项目名称:Cider-x64,代码行数:13,代码来源:LoaderFactory.cs

示例9: AssemblyExecutor

        public AssemblyExecutor(string fileNname, string domainName)
        {
            assemblyFileName = fileNname;
            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationBase = Path.GetDirectoryName(assemblyFileName);
            setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
            setup.ApplicationName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
            setup.ShadowCopyFiles = "true";
            setup.ShadowCopyDirectories = Path.GetDirectoryName(assemblyFileName);
            appDomain = AppDomain.CreateDomain(domainName, null, setup);

            remoteExecutor = (RemoteExecutor)appDomain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof(RemoteExecutor).ToString());
        }
开发者ID:KillerGoldFisch,项目名称:GCharp,代码行数:13,代码来源:AssemblyExecutor.cs

示例10: Create

        public ILoader Create()
        {
            AppDomainSetup adSetup = new AppDomainSetup();
            adSetup.ShadowCopyFiles = "true"; // not a boolean

            m_LoaderDomain = createAppDomainForLoader(adSetup);
            string dir = m_LoaderDomain.SetupInformation.ApplicationBase;

            string selfAssemblyName = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
            selfAssemblyName = Uri.UnescapeDataString(selfAssemblyName); // e.g. otherwise, spaces in the path of our .EXE would be represented as '%20'

            ILoader loader = (ILoader) m_LoaderDomain.CreateInstanceFromAndUnwrap(selfAssemblyName, "Cider_x64.Loader");
            return loader;
        }
开发者ID:kurattila,项目名称:Cider-x64,代码行数:14,代码来源:LoaderFactory.cs

示例11: CreateSiloHost

        private static SiloHost CreateSiloHost(AppDomain appDomain, ClusterConfiguration clusterConfig)
        {
            var args = new object[] { nameof(SiloInitializationIsRetryableTest), clusterConfig };

            return (SiloHost)appDomain.CreateInstanceFromAndUnwrap(
                "OrleansRuntime.dll",
                typeof(SiloHost).FullName,
                false,
                BindingFlags.Default,
                null,
                args,
                CultureInfo.CurrentCulture,
                new object[] { });
        }
开发者ID:osjimenez,项目名称:orleans,代码行数:14,代码来源:SiloInitializationTests.cs

示例12: CreateAgent

 private static DomainHostingStarterAgent CreateAgent(AppDomain domain)
 {
     try
     {
         return (DomainHostingStarterAgent)domain.CreateInstanceAndUnwrap(
             typeof(DomainHostingStarterAgent).Assembly.FullName,
             typeof(DomainHostingStarterAgent).FullName);
     }
     catch
     {
         return (DomainHostingStarterAgent)domain.CreateInstanceFromAndUnwrap(
             typeof(DomainHostingStarterAgent).Assembly.Location,
             typeof(DomainHostingStarterAgent).FullName);
     }
 }
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:15,代码来源:DomainHostingStarter.cs

示例13: Load

        // Methods ========================================================================
        public void Load(string filePath)
        {
            AssemblyPath = filePath;
            AssemblyName = Path.GetFileName(filePath);

            domain = AppDomain.CreateDomain(AssemblyName);
            proxy = (AppDomainProxy)domain.CreateInstanceFromAndUnwrap(
                Assembly.GetExecutingAssembly().CodeBase, typeof(AppDomainProxy).FullName);

            try {
                proxy.LoadAssembly(filePath);
            } catch (Exception) {
                AppDomain.Unload(domain);
                throw;
            }
        }
开发者ID:yiend,项目名称:mnncs,代码行数:17,代码来源:ModuleNode.cs

示例14: RecyclableAppDomain

			public RecyclableAppDomain (string name)
			{
				var info = new AppDomainSetup () {
					//appbase needs to allow loading this assembly, for remoting
					ApplicationBase = System.IO.Path.GetDirectoryName (typeof (TemplatingAppDomainRecycler).Assembly.Location),
					DisallowBindingRedirects = false,
					DisallowCodeDownload = true,
                    DisallowApplicationBaseProbing = false,
					ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
				};
				domain = AppDomain.CreateDomain (name, null, info);
                var t = typeof(DomainAssemblyLoader);
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                assemblyMap = (DomainAssemblyLoader) domain.CreateInstanceFromAndUnwrap(t.Assembly.Location, t.FullName);
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
                domain.AssemblyResolve += assemblyMap.Resolve;// new DomainAssemblyLoader(assemblyMap).Resolve;
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:17,代码来源:RecyclableAppDomain.cs

示例15: EfMigrator

        public EfMigrator(string assemblyPath, string qualifiedDbConfigName, string appConfigPath, string connectionString, string connectionProvider,
                          ILogger logger)
        {
            _logger = logger;

            appConfigPath = Path.GetFullPath(appConfigPath);
            if (!File.Exists(appConfigPath))
            {
                throw new EfMigrationException($"The {nameof(appConfigPath)} '{appConfigPath}' must exist.");
            }

            var domainSetup = AppDomain.CurrentDomain.SetupInformation;
            domainSetup.ConfigurationFile = appConfigPath;
            _logger.Debug($"Prepared AppDomain setup using {appConfigPath} as the appconfig.");

            var domainName = $"EfMigrator:{Guid.NewGuid()}";
            _domain = AppDomain.CreateDomain(domainName, null, domainSetup);
            _logger.Debug($"Created new AppDomain named {domainName}.");

            var type = typeof(EfMigratorBackend);

            var fullPath = Assembly.GetAssembly(typeof(EfMigratorBackend)).Location;
            //var domain = AppDomain.CurrentDomain.GetAssemblies()
            //                      .Where(x => !x.IsDynamic)
            //                      .Where(x => !x.GlobalAssemblyCache)
            //                      .Select(x => Path.GetDirectoryName(x.Location))
            //                      .Distinct();

            //var domains = string.Join(", ", domain);
            //logger.Debug($"Loading assemblies into appDomain: {domains}.");

            Debug.Assert(fullPath != null, "fullPath != null");

            var migrator = (EfMigratorBackend) _domain.CreateInstanceFromAndUnwrap(fullPath, type.FullName);
            _logger.Debug("Created new instance.");
            migrator.Initialize(assemblyPath, qualifiedDbConfigName, connectionString, connectionProvider);

            _logger.Debug($"Initialized new {nameof(EfMigratorBackend)} within {domainName}.");

            CurrentMigration = migrator.GetCurrentMigration() ?? InitialDatabase;
            var currentMigrationStr = CurrentMigration == InitialDatabase ? "$InitialDatabase" : CurrentMigration;
            _logger.Information($"Current Migration is {currentMigrationStr}.");

            _migratorBackend = migrator;
        }
开发者ID:Silvenga,项目名称:Cake.EntityFramework,代码行数:45,代码来源:EfMigrator.cs


注:本文中的System.AppDomain.CreateInstanceFromAndUnwrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。