/// <summary>
        /// Loads the decision module based on the decision metadata
        /// </summary>
        /// <param name="decisionMetadata">The decision metadata.</param>
        /// <param name="workspaceWrapper">The workspace wrapper.</param>
        /// <param name="componentsAppDomain">The components app domain is the app domain which decision assembly is going to be loaded into.</param>
        /// <returns>Loaded decision</returns>
        internal static ILoopDecisionModule LoadDecisionModule(LoopScopeMetadata loopMetadata, IWorkspaceInternal workspaceWrapper,
                                                               AppDomain componentsAppDomain)
        {
            DecisionLoader loader = ConstructDecisionModuleInComponentsAppDomain(loopMetadata, workspaceWrapper, componentsAppDomain);

            return((ILoopDecisionModule)loader.LoadedDecisionModule);
        }
        private static DecisionLoader ConstructDecisionModuleInComponentsAppDomain(IDecision decisionMetadata, IWorkspaceInternal workspaceWrapper, AppDomain componentsAppDomain)
        {
            // DecisionLoader must be MarshalByRef, otherwise the properties don't get filled out the
            // way that we want them to.
            DecisionLoader loader = (DecisionLoader)componentsAppDomain.CreateInstanceAndUnwrap(
                Assembly.GetExecutingAssembly().FullName, typeof(DecisionLoader).FullName, false,
                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance | BindingFlags.Instance, null,
                new object[] { decisionMetadata.Classname, decisionMetadata.SourceAssembly, workspaceWrapper },
                System.Globalization.CultureInfo.CurrentCulture, new object[] { });

            // Perform the actual load by passing a reference to the Loader's Load function to the new
            // AppDomain to execute
            loader.Load();
            return(loader);
        }