Exemple #1
0
        /// <summary>
        /// Creates an isolated environment for Gallio in an existing AppDomain of this process.
        /// The AppDomain will be unloaded when the isolated environment is disposed.
        /// </summary>
        /// <param name="appDomain">The AppDomain in which to create the isolated environment.</param>
        /// <param name="runtimeLocator">The runtime locator.</param>
        /// <returns>The isolated environment.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="appDomain"/>
        /// or <paramref name="runtimeLocator"/> is null.</exception>
        /// <exception cref="LoaderException">Thrown if the environment could not be created.</exception>
        public static IIsolatedEnvironment CreateIsolatedEnvironmentInExistingAppDomain(
            AppDomain appDomain, RuntimeLocator runtimeLocator)
        {
            if (appDomain == null)
            {
                throw new ArgumentNullException("appDomain");
            }
            if (runtimeLocator == null)
            {
                throw new ArgumentNullException("runtimeLocator");
            }

            string runtimePath = runtimeLocator.GetValidatedRuntimePathOrThrow();

            return(InternalCreateIsolatedEnvironment(appDomain, runtimePath));
        }
Exemple #2
0
        /// <summary>
        /// Creates an isolated environment for Gallio in a new AppDomain of this process.
        /// The AppDomain will be unloaded when the isolated environment is disposed.
        /// </summary>
        /// <param name="runtimeLocator">The runtime locator.</param>
        /// <returns>The isolated environment.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="runtimeLocator"/> is null.</exception>
        /// <exception cref="LoaderException">Thrown if the environment could not be created.</exception>
        public static IIsolatedEnvironment CreateIsolatedEnvironment(RuntimeLocator runtimeLocator)
        {
            if (runtimeLocator == null)
            {
                throw new ArgumentNullException("runtimeLocator");
            }

            string runtimePath = runtimeLocator.GetValidatedRuntimePathOrThrow();

            AppDomainSetup appDomainSetup = new AppDomainSetup();

            appDomainSetup.ApplicationName = "Gallio";
            appDomainSetup.ApplicationBase = runtimePath;
            Evidence      evidence             = AppDomain.CurrentDomain.Evidence;
            PermissionSet defaultPermissionSet = new PermissionSet(PermissionState.Unrestricted);

            StrongName[] fullTrustAssemblies = new StrongName[0];
            AppDomain    appDomain           = AppDomain.CreateDomain(appDomainSetup.ApplicationName, evidence,
                                                                      appDomainSetup, defaultPermissionSet, fullTrustAssemblies);

            return(InternalCreateIsolatedEnvironment(appDomain, runtimePath));
        }