public AddInServerWorker CreateDomain(AddInToken token, PermissionSet permissionSet) { AppDomain domain; AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = Path.GetDirectoryName(token._addin.Location); setup.ConfigurationFile = token._addin.Location + ".config"; Assembly sysCore = typeof(AddInActivator).Assembly; domain = AppDomain.CreateDomain(token.Name, AppDomain.CurrentDomain.Evidence, setup, permissionSet, AddInActivator.CreateStrongName(sysCore)); // Grant full trust to System.Core.dll // Ensure we load System.Core.dll in this new AD. domain.Load(sysCore.FullName); ObjectHandle workerHandle = Activator.CreateInstance(domain, sysCore.FullName, typeof(AddInServerWorker).FullName); AddInServerWorker server = (AddInServerWorker)workerHandle.Unwrap(); server.AddInServer = this; Interlocked.Increment(ref _addInAppDomains); return(server); }
internal static T Activate <T>(AddInToken token, AddInProcess process, PermissionSet permissionSet) { if (token == null) { throw new ArgumentNullException("token"); } if (permissionSet == null) { throw new ArgumentNullException("permissionSet"); } if (process == null) { throw new ArgumentNullException("process"); } System.Diagnostics.Contracts.Contract.EndContractBlock(); // check that they have ExecutionPermission. Otherwise OOP remoting fails // by shutting down the pipe, leaving the user scratching his head. if (!permissionSet.IsUnrestricted()) { SecurityPermission p = (SecurityPermission)permissionSet.GetPermission(typeof(SecurityPermission)); SecurityPermissionFlag requiredFlags = SecurityPermissionFlag.Execution; if (p == null || (p.Flags & requiredFlags) != requiredFlags) { throw new ArgumentException(Res.NeedSecurityFlags); } } RemotingHelper.InitializeClientChannel(); AddInServer addInServer = process.GetAddInServer(); AddInServerWorker addInServerWorker = addInServer.CreateDomain(token, permissionSet); AddInEnvironment fullEnvironment = new AddInEnvironment(process, addInServerWorker); return(ActivateOutOfProcess <T>(token, fullEnvironment, true)); }
internal AddInEnvironment(AddInProcess process, AddInServerWorker worker) { _addInServerWorker = worker; _process = process; }