private static Context PrepareNewContext(AppDomain appDomain, ContextFactory factory) { Context cx = new Context (appDomain); if (cx.factory != null || cx.enterCount != 0) { throw new ApplicationException ("factory.makeContext() returned Context instance already associated with some thread"); } cx.factory = factory; factory.FireOnContextCreated (cx); if (factory.Sealed && !cx.Sealed) { cx.Seal ((object)null); } Thread.SetData (LocalSlot, cx); return cx; }