System.Runtime.Hosting.ApplicationActivator.CreateInstanceHelper C# (CSharp) Method

CreateInstanceHelper() protected static method

protected static CreateInstanceHelper ( AppDomainSetup adSetup ) : ObjectHandle
adSetup AppDomainSetup
return System.Runtime.Remoting.ObjectHandle
        protected static ObjectHandle CreateInstanceHelper (AppDomainSetup adSetup) {
            if (adSetup.ActivationArguments == null)
                throw new ArgumentException(Environment.GetResourceString("Arg_MissingActivationArguments"));

            adSetup.ActivationArguments.ActivateInstance = true;
            // inherit the caller's domain evidence for the activation.
            Evidence activatorEvidence = AppDomain.CurrentDomain.Evidence;
            // add the application identity as an evidence.
            Evidence appEvidence = CmsUtils.MergeApplicationEvidence(null,
                                                                     adSetup.ActivationArguments.ApplicationIdentity,
                                                                     adSetup.ActivationArguments.ActivationContext,
                                                                     adSetup.ActivationArguments.ActivationData);

            HostSecurityManager securityManager = AppDomain.CurrentDomain.HostSecurityManager;
            ApplicationTrust appTrust = securityManager.DetermineApplicationTrust(appEvidence, activatorEvidence, new TrustManagerContext());
            if (appTrust == null || !appTrust.IsApplicationTrustedToRun)
                throw new PolicyException(Environment.GetResourceString("Policy_NoExecutionPermission"), 
                                          System.__HResults.CORSEC_E_NO_EXEC_PERM,
                                          null);

            ObjRef or = AppDomain.nCreateInstance(adSetup.ActivationArguments.ApplicationIdentity.FullName,
                                                  adSetup,
                                                  appEvidence,
                                                  appEvidence == null ? AppDomain.CurrentDomain.InternalEvidence : null,
                                                  AppDomain.CurrentDomain.GetSecurityDescriptor());
            if (or == null)
                return null;
            return RemotingServices.Unmarshal(or) as ObjectHandle;
        }
    }

Usage Example

Esempio n. 1
0
        /// <summary>Creates an instance of the application to be activated, using the specified activation context  and custom activation data.  </summary>
        /// <returns>An <see cref="T:System.Runtime.Remoting.ObjectHandle" /> that is a wrapper for the return value of the application execution. The return value must be unwrapped to access the real object.</returns>
        /// <param name="activationContext">An <see cref="T:System.ActivationContext" /> that identifies the application to activate.</param>
        /// <param name="activationCustomData">Custom activation data.</param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="activationContext" /> is null. </exception>
        public virtual ObjectHandle CreateInstance(ActivationContext activationContext, string[] activationCustomData)
        {
            if (activationContext == null)
            {
                throw new ArgumentNullException("activationContext");
            }
            AppDomainSetup adSetup = new AppDomainSetup(activationContext);

            return(ApplicationActivator.CreateInstanceHelper(adSetup));
        }
All Usage Examples Of System.Runtime.Hosting.ApplicationActivator::CreateInstanceHelper