protected void LoadInCurrentDomain(string fullTypeName, ASCOMClient ascomClient) { string[] tokens = fullTypeName.Split(new char[] { ',' }, 2); m_AssemblyName = new AssemblyName(tokens[1]); m_HostDomain = null; Assembly asm = Assembly.Load(m_AssemblyName); object obj = asm.CreateInstance(tokens[0]); m_Instance = (IIsolatedDevice)obj; m_Instance.Initialise(new OccuRecHostDelegate(tokens[0], ascomClient)); }
protected void LoadInAppDomain(string fullTypeName, ASCOMClient ascomClient) { string[] tokens = fullTypeName.Split(new char[] { ',' }, 2); m_AssemblyName = new AssemblyName(tokens[1]); var appSetup = new AppDomainSetup() { ApplicationName = "OccuRec", ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile }; m_DomainName = string.Format("{0}{1}.v{2}", APP_DOMAIN_PREFIX, m_AssemblyName.Name, m_AssemblyName.Version != null ? m_AssemblyName.Version.ToString() : "XX"); var e = new Evidence(); e.AddHostEvidence(new Zone(SecurityZone.MyComputer)); PermissionSet pset = SecurityManager.GetStandardSandbox(e); m_HostDomain = AppDomain.CreateDomain(m_DomainName, AppDomain.CurrentDomain.Evidence, appSetup, pset, null); m_HostDomain.AssemblyResolve += m_HostDomain_AssemblyResolve; m_HostDomain.ReflectionOnlyAssemblyResolve += m_HostDomain_AssemblyResolve; m_HostDomain.UnhandledException += m_HostDomain_UnhandledException; m_HostDomain.DomainUnload += m_HostDomain_DomainUnload; object obj = m_HostDomain.CreateInstanceAndUnwrap(tokens[1], tokens[0]); ascomClient.RegisterLifetimeService(obj as MarshalByRefObject); m_Instance = (IIsolatedDevice)obj; m_Instance.Initialise(new OccuRecHostDelegate(tokens[0], ascomClient)); }