static void Main(string[] args)
        {
            var fullPathToDll = "HelloWorld2.dll";
            var domainSetup   = new AppDomainSetup
            {
                ApplicationBase = Environment.CurrentDirectory,
                PrivateBinPath  = fullPathToDll
            };

            var ev1 = new Evidence();

            ev1.AddAssemblyEvidence(new ApplicationDirectory(typeof(Class1).Assembly.FullName));

            ev1.AddHostEvidence(new Zone(SecurityZone.MyComputer));

            var ad = AppDomain.CreateDomain("Class1", ev1, domainSetup, Assembly.GetExecutingAssembly().PermissionSet, null);

            var identity  = new GenericIdentity("Class1");
            var principal = new GenericPrincipal(identity, null);

            ad.SetThreadPrincipal(principal);

            var remoteWorker = (Class1)ad.CreateInstanceFromAndUnwrap(
                fullPathToDll,
                typeof(Class1).FullName);

            remoteWorker.ExcuteMe();
        }
        //</Snippet2>

        //<Snippet5>
        public override Evidence ProvideAssemblyEvidence(Assembly loadedAssembly, Evidence evidence)
        {
            Console.WriteLine("Provide assembly evidence for: " + (loadedAssembly == null ? "Unknown" : loadedAssembly.ToString()) + ".");
            if (evidence == null)
            {
                return(null);
            }

            evidence.AddAssemblyEvidence(new CustomEvidenceType());
            return(evidence);
        }
        public void LoadActionPlugins()
        {
            var dir = new DirectoryInfo(Path.Combine(Application.StartupPath, Settings.Default.PluginFolder));

            IEnumerable <FileInfo> dlls = dir.EnumerateFiles(@"*.dll", SearchOption.AllDirectories);

            List <Type> actions = new List <Type>();

            foreach (FileInfo fi in dlls)
            {
                var evidence = new Evidence();
                var appDir   = new ApplicationDirectory(Assembly.GetEntryAssembly().CodeBase);
                evidence.AddAssemblyEvidence(appDir);
                Assembly asm;
                try
                {
                    asm = Assembly.LoadFrom(fi.FullName);
                }
                catch (BadImageFormatException)
                {
                    continue;
                }

                Type[] typesInFile = asm.GetExportedTypes();

                var actionTypes = (from type in typesInFile
                                   where !type.IsAbstract
                                   where type.GetCustomAttributes(typeof(ActionCategoryAttribute), true).Any()
                                   select type);

                List <Type> actionTypeList = actionTypes.ToList();
                if (!actionTypeList.Any())
                {
                    continue;
                }

                this.PluginFiles.Add(fi, actionTypeList);

                var customDataTypes = from type in typesInFile
                                      where !type.IsAbstract
                                      where type.IsAssignableFrom(typeof(ICentipedeDataType))
                                      select type;

                foreach (Type t in customDataTypes)
                {
                    CentipedeSerializer.RegisterSerializableType(t);
                }
            }
        }