當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。