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


C# AppDomain.CreateInstanceAndUnwrap方法代码示例

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


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

示例1: CreateAppDomain

        private ICustomConfigAssemblyInspector CreateAppDomain()
        {
            AppDomainSetup setup = new AppDomainSetup();


#if DEBUG
            setup.ApplicationBase = @"E:\db4object\db4o\Trunk\omn\OMADDIN\bin\";
#else 
            setup.ApplicationBase = CommonForAppDomain.GetPath() + "\\";
#endif


            setup.ShadowCopyDirectories = Path.GetTempPath();
            setup.ShadowCopyFiles = "true";
            workerAppDomain = AppDomain.CreateDomain("CustomConfigWorkerAppDomain", null, setup);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            object anObject = workerAppDomain.CreateInstanceAndUnwrap("OMCustomConfigImplementation",
                                                                      "OMCustomConfigImplementation.CustomConfigAssemblyInfo.CustomConfigAssemblyInspector");
            ICustomConfigAssemblyInspector customConfigAssemblyInspector = anObject as ICustomConfigAssemblyInspector;

            object anObject1 = workerAppDomain.CreateInstanceAndUnwrap("OMCustomConfigImplementation",
                                                                        "OMCustomConfigImplementation.UserCustomConfig.UserConfig");
            IUserConfig conn = anObject1 as IUserConfig;
            CustomConfigInspectorObject.CustomUserConfig = conn;
           
            return customConfigAssemblyInspector;
        }
开发者ID:superyfwy,项目名称:db4o,代码行数:27,代码来源:CustomConfigAppDomain.cs

示例2: RunScriptCore

 private void RunScriptCore(byte[] inMemoryAssembly, byte[] inMemorySymbolStore, TextWriter outputTextWriter, TextWriter errorTextWriter)
 {
     RemoteScriptRun scriptRun;
     lock (fieldsLock)
     {
         if (inMemoryAssembly != loadedAssembly)
         {
             if (scriptAppDomain != null)
             {
                 AppDomain.Unload(scriptAppDomain);
             }
             scriptAppDomain = AppDomain.CreateDomain("ScriptAppDomain");
             remoteScriptRun = (RemoteScriptRun)scriptAppDomain.CreateInstanceAndUnwrap(typeof(RemoteScriptRun).Assembly.FullName, typeof(RemoteScriptRun).FullName);
             remoteScriptRun.Load(inMemoryAssembly, inMemorySymbolStore, outputTextWriter, errorTextWriter);
             loadedAssembly = inMemoryAssembly;
         }
         scriptRun = remoteScriptRun;
     }
     
     try
     {
         scriptRun?.Run();
     }
     catch (AppDomainUnloadedException)
     {
     }
 }
开发者ID:jhorv,项目名称:dotnetpad,代码行数:27,代码来源:ScriptHost.cs

示例3: Start

        /// <summary>
        /// Starts this instance.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Job already started.</exception>
        public static void Start()
        {
            if (_job != null)
                throw new InvalidOperationException("Job already started.");

            var evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
            var setup = new AppDomainSetup
            {
                ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                ShadowCopyFiles = "false"
            };

            _appDomain = AppDomain.CreateDomain("eSync-" + Guid.NewGuid(), evidence, setup);
            try
            {
                var assembly = _appDomain.Load(typeof(SyncServiceJob).Assembly.GetName());
                var jobTypeName = typeof(SyncServiceJob).FullName;

                _job = (IJob)_appDomain.CreateInstanceAndUnwrap(assembly.FullName, jobTypeName);
                _job.Start();
            }
            catch
            {
                _job = null;
                AppDomain.Unload(_appDomain);
                _appDomain = null;

                throw;
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:34,代码来源:ESyncJob.cs

示例4: RemoteDebugger

        public RemoteDebugger()
        {
            // Create a new debugger session
            mSessionId = Guid.NewGuid().ToString();

            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
            AppDomainSetup appDomainSetup = AppDomain.CurrentDomain.SetupInformation;

            mAppDomain = AppDomain.CreateDomain(String.Format("Debugger-{0}", mSessionId), evidence, appDomainSetup);

            /*
            Type assemblyLoaderType = typeof(AssemblyLoader);
            AssemblyLoader loader = mAppDomain.CreateInstanceAndUnwrap(assemblyLoaderType.Assembly.GetName().Name, assemblyLoaderType.FullName) as AssemblyLoader;

            foreach (String assemblyPath in Directory.GetFiles(DebuggerConfig.ApplicationPath, "Tridion*.dll"))
            {
                loader.LoadAssembly(assemblyPath);
            }
            */
            Type debuggerHostType = typeof(DebugEngineServer);

            mDebuggerHost = mAppDomain.CreateInstanceAndUnwrap(
                debuggerHostType.Assembly.GetName().Name,
                debuggerHostType.FullName,
                true,
                BindingFlags.Default,
                null,
                new Object[] { mSessionId },
                null,
                null) as DebugEngineServer;
        }
开发者ID:mvlasenko,项目名称:TridionVSRazorExtension,代码行数:31,代码来源:RemoteDebugger.cs

示例5: DiaSessionWrapper

        public DiaSessionWrapper(string assemblyFilename)
        {
            session = new DiaSession(assemblyFilename);

            var setup = new AppDomainSetup
            {
                ApplicationBase = Path.GetDirectoryName(new Uri(typeof(DiaSessionWrapperHelper).Assembly.CodeBase).LocalPath),
                ApplicationName = Guid.NewGuid().ToString(),
                LoaderOptimization = LoaderOptimization.MultiDomainHost,
                ShadowCopyFiles = "true",
            };

            setup.ShadowCopyDirectories = setup.ApplicationBase;
            setup.CachePath = Path.Combine(Path.GetTempPath(), setup.ApplicationName);

            appDomain = AppDomain.CreateDomain(setup.ApplicationName, null, setup, new PermissionSet(PermissionState.Unrestricted));

            helper = (DiaSessionWrapperHelper)appDomain.CreateInstanceAndUnwrap(
                assemblyName: typeof(DiaSessionWrapperHelper).Assembly.FullName,
                typeName: typeof(DiaSessionWrapperHelper).FullName,
                ignoreCase: false,
                bindingAttr: 0,
                binder: null,
                args: new[] { assemblyFilename },
                culture: null,
                activationAttributes: null,
                securityAttributes: null
            );
        }
开发者ID:JayBazuzi,项目名称:xunit,代码行数:29,代码来源:DiaSessionWrapper.cs

示例6: Run

        public ContextWrapper Run(string tagOrClassName, RunnerInvocation invocation, Func<RunnerInvocation, ContextWrapper> action, string dll)
        {
            this.dll = dll;

            var setup = new AppDomainSetup();

            setup.ConfigurationFile = Path.GetFullPath(config);

            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            domain = AppDomain.CreateDomain("NSpecRunnerDomain.Run", null, setup);

            var type = typeof(Wrapper);

            var assemblyName = type.Assembly.GetName().Name;

            var typeName = type.FullName;

            domain.AssemblyResolve += Resolve;

            var wrapper = (Wrapper)domain.CreateInstanceAndUnwrap(assemblyName, typeName);

            var results = wrapper.Execute(invocation, action);// RunContexts(tagOrClassName);

            AppDomain.Unload(domain);

            return results;
        }
开发者ID:abhishek-t,项目名称:SpecRunner,代码行数:28,代码来源:NSpecDomain.cs

示例7: StartInternal

        private void StartInternal()
        {
            ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(_configurationFilePath);
            CopyStubAssemblyToRoleDirectory(_appDomainSetup.ApplicationBase, _role);
            _appDomain = AppDomain.CreateDomain("LightBlue", null, _appDomainSetup);
            _hostStub = (HostStub)_appDomain.CreateInstanceAndUnwrap(typeof(HostStub).Assembly.FullName, typeof(HostStub).FullName);

            var shipper = new EventTraceShipper();
            Action<string> twh = m => _role.TraceWrite(Identifier, m);
            Action<string> twlh = m => _role.TraceWriteLine(Identifier, m);
            shipper.TraceWrite += twh;
            shipper.TraceWriteLine += twlh;
            _hostStub.ConfigureTracing(shipper);

            // TODO: decide how this is going to work.
            _appDomain.UnhandledException += StubExceptionHandler.Handler;

            try
            {
                _started.SetResult(new object());
                _role.TraceWriteLine(Identifier, "Role started in app domain: " + _appDomain.Id + " by " + Thread.CurrentThread.Name);
                _hostStub.Run(_assemblyFilePath, _configurationFilePath, _serviceDefinitionFilePath, _roleName, false);
            }
            catch (Exception ex)
            {
                _role.TraceWriteLine(Identifier, ex.ToString());
            }
            finally
            {
                shipper.TraceWrite -= twh;
                shipper.TraceWriteLine -= twlh;
                _completed.SetResult(new object());
            }
        }
开发者ID:zconduit,项目名称:LightBlue,代码行数:34,代码来源:AppDomainRunner.cs

示例8: InitliazeValidationAppDomain

        private void InitliazeValidationAppDomain()
        {
            m_ValidationAppDomain = AppDomain.CreateDomain("ValidationDomain", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.BaseDirectory, string.Empty, false);

            var validatorType = typeof(TypeValidator);
            m_Validator = (TypeValidator)m_ValidationAppDomain.CreateInstanceAndUnwrap(validatorType.Assembly.FullName, validatorType.FullName);
        }
开发者ID:zesus19,项目名称:c5.v1,代码行数:7,代码来源:AppDomainBootstrap.cs

示例9: CustomWindowsFormsHost

 /// <summary>
 /// Creates a new CustomWindowsFormsHost instance that allows hosting controls
 /// from the specified AppDomain.
 /// </summary>
 public CustomWindowsFormsHost(AppDomain childDomain)
 {
     var type = typeof(HostedControlContainer);
     this._container =
         (HostedControlContainer)childDomain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
     Init();
 }
开发者ID:MyLoadTest,项目名称:VuGenAddinManager,代码行数:11,代码来源:CustomWindowsFormsHost.cs

示例10: Run

        public void Run(RunnerInvocation invocation, Action<RunnerInvocation> action, string dll)
        {
            this.dll = dll;

            var setup = new AppDomainSetup();

            setup.ConfigurationFile = Path.GetFullPath(config);

            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            domain = AppDomain.CreateDomain("NSpecDomain.Run", null, setup);

            var type = typeof(Wrapper);

            var assemblyName = type.Assembly.GetName().Name;

            var typeName = type.FullName;

            domain.AssemblyResolve += Resolve;

            var wrapper = (Wrapper)domain.CreateInstanceAndUnwrap(assemblyName, typeName);

            wrapper.Execute(invocation, action);

            AppDomain.Unload(domain);
        }
开发者ID:ericbock,项目名称:NSpec,代码行数:26,代码来源:NSpecDomain.cs

示例11: AssertAppDomainHasAssemblyResolveEventSubscribers

        internal static void AssertAppDomainHasAssemblyResolveEventSubscribers(int expected, AppDomain appDomain)
        {
            var proxy = (AppDomainInfoProvider)appDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(AppDomainInfoProvider).FullName);
            var subscriberCount = proxy.GetAssemblyResolveEventSubscriberCount();

            Assert.Equal(expected, subscriberCount);
        }
开发者ID:sjwood,项目名称:EmbeddedFx,代码行数:7,代码来源:GivenAnEmbeddedAssemblyLoader.cs

示例12: LoadFrom

        public void LoadFrom(string path)
        {
            if (_domain != null)
            {
                _scanner.Teardown();
                AppDomain.Unload(_domain);
            }

            var name = Path.GetFileNameWithoutExtension(path);
            var dirPath = Path.GetFullPath(Path.GetDirectoryName(path));

            var setup = new AppDomainSetup
            {
                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                PrivateBinPath = dirPath,
                ShadowCopyFiles = "true",
                ShadowCopyDirectories = dirPath,
            };

            _domain = AppDomain.CreateDomain(name + "Domain", AppDomain.CurrentDomain.Evidence, setup);

            var scannerType = typeof(Scanner);
            _scanner = (Scanner)_domain.CreateInstanceAndUnwrap(scannerType.Assembly.FullName, scannerType.FullName);
            _scanner.Load(name);
            _scanner.Setup();
        }
开发者ID:robert-impey,项目名称:PluginDemo,代码行数:26,代码来源:AssemblyManager.cs

示例13: Init

        void Init(string fileNname, string domainName)
        {
            //difference comparing to InitLagacy:
            // CreateInstanceAndUnwrap instead of CreateInstanceFromAndUnwrap
            //
            // setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            // instead of setup.ApplicationBase = Path.GetDirectoryName(assemblyFileName); 
            //
            // In 2016 just discovered that InitLegacy doesn't longer work. May be because some changes in .NET versions...  
            // This is a low impact change as AssemblyExecutor is only used for cached vs. non-cached execution in stand alone 
            // hosting mode.

            assemblyFileName = fileNname;

            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
            setup.ApplicationName = Utils.GetAssemblyFileName(Assembly.GetExecutingAssembly());
            setup.ShadowCopyFiles = "true";
            setup.ShadowCopyDirectories = Path.GetDirectoryName(assemblyFileName);

            appDomain = AppDomain.CreateDomain(domainName, null, setup);
            remoteExecutor = (RemoteExecutor)appDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(RemoteExecutor).ToString());
            remoteExecutor.searchDirs = ExecuteOptions.options.searchDirs;
        }
开发者ID:oleg-shilo,项目名称:cs-script,代码行数:25,代码来源:AssemblyExecutor.cs

示例14: Invoke

 public static bool Invoke(AppDomain domain, ScriptEnvironmentSetup setup, out RemoteScriptEnvironment environment) {
     RemoteDelegate rd = (RemoteDelegate)domain.CreateInstanceAndUnwrap(typeof(RemoteDelegate).Assembly.FullName,
         typeof(RemoteDelegate).FullName, false, BindingFlags.Default, null, new object[] { setup }, null, null, null);
     
     environment = rd.Environment;
     return rd.NewCreated;
 }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:7,代码来源:ScriptEnvironment.Remote.cs

示例15: CreateRemoteHost

 protected override HostedService CreateRemoteHost(AppDomain appDomain)
 {
     object instance = appDomain.CreateInstanceAndUnwrap("Rhino.ServiceBus",
                                                         "Rhino.ServiceBus.LoadBalancer.LoadBalancerHost");
     var hoster = (LoadBalancerHost)instance;
     return new HostedService(hoster, "Rhino.ServiceBus", appDomain);
 }
开发者ID:eyantiful,项目名称:rhino-esb,代码行数:7,代码来源:RemoteAppDomainLoadBalancerHost.cs


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