/// <summary> /// Creates a <see cref="Sandbox"/> object, compiled expressions and configures extensions inside the sandbox application domain. /// </summary> /// <param name="appDomain">The sandbox application domain.</param> /// <param name="assemblyPath">The compiled expressions assembly path.</param> /// <param name="extensions">The extensions to initialize the compiled expression object with.</param> /// <returns>A remote <see cref="Sandbox"/> object.</returns> private static Sandbox CreateSandbox(AppDomain appDomain, string assemblyPath, ExtensionCollection extensions) { var sandboxType = typeof(Sandbox); var sandboxAssemblyPath = sandboxType.Assembly.ManifestModule.FullyQualifiedName; var typeName = sandboxType.FullName; Debug.Assert(typeName != null, "typeName != null"); var sandbox = (Sandbox)Activator.CreateInstanceFrom(appDomain, sandboxAssemblyPath, typeName).Unwrap(); var assemblyMap = new Dictionary<string, string>(); foreach (var type in extensions.Select(e => e.GetExtensionType())) assemblyMap[type.Assembly.FullName] = type.Assembly.ManifestModule.FullyQualifiedName; sandbox.InstallAssemblyResolver(assemblyMap); sandbox.CreateCompiledExpressions(assemblyPath); // Extensions foreach (var extension in extensions) sandbox.SetValue(extension.Name, extension.Instance); return sandbox; }