public AppInvokeEntryPointResult FindForm(AppDomain ad, string assemblyFile, string configFile)
        {
            //IAppInvokeEntryPoint result = null;
            AppInvokeEntryPointResult result = new AppInvokeEntryPointResult();

            try
            {
                // Load the primary assembly here
                Assembly asmEntryPoint = Assembly.LoadFrom(assemblyFile);

                // other assemblies
                Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();

                // entry point
                if (asmEntryPoint.EntryPoint == null)
                {
                    // find the entry point assembly
                    foreach (Assembly asm in asms)
                    {
                        if (asm.EntryPoint != null)
                        {
                            asmEntryPoint = asm;
                            break;
                        }
                    }
                }

                // Load all the assemblies
                IDictionary <string, string> loadedAssemblies = result.LoadedAssemblies;
                foreach (Assembly asm in asms)
                {
                    string fullName = asm.FullName;
                    if (!loadedAssemblies.ContainsKey(fullName))
                    {
                        loadedAssemblies.Add(fullName, asm.Location);
                    }

                    foreach (var asmRef in asm.GetReferencedAssemblies())
                    {
                        fullName = asmRef.FullName;

                        if (!loadedAssemblies.ContainsKey(fullName))
                        {
                            Assembly asm2 = ad.Load(asmRef);
                            loadedAssemblies.Add(fullName, asm2.Location);
                        }
                    }
                }

                // find the entry point class implements our interface
                Type typeEntryPoint = asmEntryPoint.EntryPoint.DeclaringType;
                if (typeof(IAppInvokeEntryPoint).IsAssignableFrom(typeEntryPoint))
                {
                    AssemblyName asm = AssemblyName.GetAssemblyName(assemblyFile);
                    //result = ad.CreateInstanceAndUnwrap(asm.FullName, typeEntryPoint.FullName) as IAppInvokeEntryPoint;
                    result.AssemblyName = asm.FullName;
                    result.TypeName     = typeEntryPoint.FullName;
                    result.Instance     = ad.CreateInstance(asm.FullName, typeEntryPoint.FullName);
                }
            }
            catch (Exception ex)
            {
                ExceptionManagement.ExceptionManager.Publish(ex);
            }

            return(result);
        }
        public AppInvokeEntryPointResult FindForm(AppDomain ad, string assemblyFile, string configFile)
        {
            //IAppInvokeEntryPoint result = null;
            AppInvokeEntryPointResult result = new AppInvokeEntryPointResult();

            try
            {
                // Load the primary assembly here
                Assembly asmEntryPoint = Assembly.LoadFrom(assemblyFile);

                // other assemblies
                Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();

                // entry point
                if (asmEntryPoint.EntryPoint == null)
                {
                    // find the entry point assembly
                    foreach (Assembly asm in asms)
                    {
                        if (asm.EntryPoint != null)
                        {
                            asmEntryPoint = asm;
                            break;
                        }
                    }
                }

                // Load all the assemblies                
                IDictionary<string, string> loadedAssemblies = result.LoadedAssemblies;
                foreach (Assembly asm in asms)
                {
                    string fullName = asm.FullName;
                    if (!loadedAssemblies.ContainsKey(fullName))
                    {
                        loadedAssemblies.Add(fullName, asm.Location);
                    }

                    foreach (var asmRef in asm.GetReferencedAssemblies())
                    {
                        fullName = asmRef.FullName;

                        if (!loadedAssemblies.ContainsKey(fullName))
                        {
                            Assembly asm2 = ad.Load(asmRef);
                            loadedAssemblies.Add(fullName, asm2.Location);
                        }
                    }
                }

                // find the entry point class implements our interface
                Type typeEntryPoint = asmEntryPoint.EntryPoint.DeclaringType;
                if (typeof(IAppInvokeEntryPoint).IsAssignableFrom(typeEntryPoint))
                {
                    AssemblyName asm = AssemblyName.GetAssemblyName(assemblyFile);
                    //result = ad.CreateInstanceAndUnwrap(asm.FullName, typeEntryPoint.FullName) as IAppInvokeEntryPoint;
                    result.AssemblyName = asm.FullName;
                    result.TypeName = typeEntryPoint.FullName;
                    result.Instance = ad.CreateInstance(asm.FullName, typeEntryPoint.FullName);
                }
            }
            catch (Exception ex)
            {
                ExceptionManagement.ExceptionManager.Publish(ex);
            }

            return result;
        }