mscorlib(4.0.0.0) API with additions
AppDomain.cs
1 using System.Collections;
6 using System.IO;
7 using System.Reflection;
12 using System.Runtime.Hosting;
15 using System.Runtime.Remoting;
19 using System.Security;
21 using System.Security.Policy;
23 using System.Security.Util;
24 using System.Text;
25 using System.Threading;
26 
27 namespace System
28 {
30  [ClassInterface(ClassInterfaceType.None)]
31  [ComDefaultInterface(typeof(_AppDomain))]
32  [ComVisible(true)]
34  {
35  [Flags]
36  private enum APPX_FLAGS
37  {
38  APPX_FLAGS_INITIALIZED = 0x1,
39  APPX_FLAGS_APPX_MODEL = 0x2,
40  APPX_FLAGS_APPX_DESIGN_MODE = 0x4,
41  APPX_FLAGS_APPX_NGEN = 0x8,
42  APPX_FLAGS_APPX_MASK = 0xE,
43  APPX_FLAGS_API_CHECK = 0x10
44  }
45 
46  private class NamespaceResolverForIntrospection
47  {
48  private IEnumerable<string> _packageGraphFilePaths;
49 
50  public NamespaceResolverForIntrospection(IEnumerable<string> packageGraphFilePaths)
51  {
52  _packageGraphFilePaths = packageGraphFilePaths;
53  }
54 
55  [SecurityCritical]
56  public void ResolveNamespace(object sender, NamespaceResolveEventArgs args)
57  {
58  IEnumerable<string> enumerable = WindowsRuntimeMetadata.ResolveNamespace(args.NamespaceName, null, _packageGraphFilePaths);
59  foreach (string item in enumerable)
60  {
62  }
63  }
64  }
65 
66  [Serializable]
67  private class EvidenceCollection
68  {
69  public Evidence ProvidedSecurityInfo;
70 
71  public Evidence CreatorsSecurityInfo;
72  }
73 
74  private class CAPTCASearcher : IComparer
75  {
76  int IComparer.Compare(object lhs, object rhs)
77  {
78  AssemblyName assemblyName = new AssemblyName((string)lhs);
79  AssemblyName assemblyName2 = (AssemblyName)rhs;
80  int num = string.Compare(assemblyName.Name, assemblyName2.Name, StringComparison.OrdinalIgnoreCase);
81  if (num != 0)
82  {
83  return num;
84  }
85  byte[] publicKeyToken = assemblyName.GetPublicKeyToken();
86  byte[] publicKeyToken2 = assemblyName2.GetPublicKeyToken();
87  if (publicKeyToken == null)
88  {
89  return -1;
90  }
91  if (publicKeyToken2 == null)
92  {
93  return 1;
94  }
95  if (publicKeyToken.Length < publicKeyToken2.Length)
96  {
97  return -1;
98  }
99  if (publicKeyToken.Length > publicKeyToken2.Length)
100  {
101  return 1;
102  }
103  for (int i = 0; i < publicKeyToken.Length; i++)
104  {
105  byte b = publicKeyToken[i];
106  byte b2 = publicKeyToken2[i];
107  if (b < b2)
108  {
109  return -1;
110  }
111  if (b > b2)
112  {
113  return 1;
114  }
115  }
116  return 0;
117  }
118  }
119 
120  [SecurityCritical]
121  private AppDomainManager _domainManager;
122 
123  private Dictionary<string, object[]> _LocalStore;
124 
125  private AppDomainSetup _FusionStore;
126 
127  private Evidence _SecurityIdentity;
128 
129  private object[] _Policies;
130 
131  [SecurityCritical]
132  private ResolveEventHandler _TypeResolve;
133 
134  [SecurityCritical]
135  private ResolveEventHandler _ResourceResolve;
136 
137  [SecurityCritical]
138  private ResolveEventHandler _AssemblyResolve;
139 
140  private Context _DefaultContext;
141 
142  private ActivationContext _activationContext;
143 
144  private ApplicationIdentity _applicationIdentity;
145 
146  private ApplicationTrust _applicationTrust;
147 
148  private IPrincipal _DefaultPrincipal;
149 
150  private DomainSpecificRemotingData _RemotingData;
151 
152  private EventHandler _processExit;
153 
154  private EventHandler _domainUnload;
155 
156  private UnhandledExceptionEventHandler _unhandledException;
157 
158  private string[] _aptcaVisibleAssemblies;
159 
160  private Dictionary<string, object> _compatFlags;
161 
162  private EventHandler<FirstChanceExceptionEventArgs> _firstChanceException;
163 
164  private IntPtr _pDomain;
165 
166  private PrincipalPolicy _PrincipalPolicy;
167 
168  private bool _HasSetPolicy;
169 
170  private bool _IsFastFullTrustDomain;
171 
172  private bool _compatFlagsInitialized;
173 
174  internal const string TargetFrameworkNameAppCompatSetting = "TargetFrameworkName";
175 
176  private static APPX_FLAGS s_flags;
177 
178  internal const int DefaultADID = 1;
179 
180  private static APPX_FLAGS Flags
181  {
182  [SecuritySafeCritical]
183  get
184  {
185  if (s_flags == (APPX_FLAGS)0)
186  {
187  s_flags = nGetAppXFlags();
188  }
189  return s_flags;
190  }
191  }
192 
193  internal static bool ProfileAPICheck
194  {
195  [SecuritySafeCritical]
196  get
197  {
198  return (Flags & APPX_FLAGS.APPX_FLAGS_API_CHECK) != (APPX_FLAGS)0;
199  }
200  }
201 
202  internal static bool IsAppXNGen
203  {
204  [SecuritySafeCritical]
205  get
206  {
207  return (Flags & APPX_FLAGS.APPX_FLAGS_APPX_NGEN) != (APPX_FLAGS)0;
208  }
209  }
210 
211  internal string[] PartialTrustVisibleAssemblies
212  {
213  get
214  {
215  return _aptcaVisibleAssemblies;
216  }
217  [SecuritySafeCritical]
218  set
219  {
220  _aptcaVisibleAssemblies = value;
221  string canonicalConditionalAptcaList = null;
222  if (value != null)
223  {
224  StringBuilder stringBuilder = StringBuilderCache.Acquire();
225  for (int i = 0; i < value.Length; i++)
226  {
227  if (value[i] != null)
228  {
229  stringBuilder.Append(value[i].ToUpperInvariant());
230  if (i != value.Length - 1)
231  {
232  stringBuilder.Append(';');
233  }
234  }
235  }
236  canonicalConditionalAptcaList = StringBuilderCache.GetStringAndRelease(stringBuilder);
237  }
238  SetCanonicalConditionalAptcaList(canonicalConditionalAptcaList);
239  }
240  }
241 
245  {
246  [SecurityCritical]
247  get
248  {
249  return _domainManager;
250  }
251  }
252 
254  {
255  [SecurityCritical]
256  get
257  {
258  HostSecurityManager hostSecurityManager = null;
260  if (domainManager != null)
261  {
262  hostSecurityManager = domainManager.HostSecurityManager;
263  }
264  if (hostSecurityManager == null)
265  {
266  hostSecurityManager = new HostSecurityManager();
267  }
268  return hostSecurityManager;
269  }
270  }
271 
275 
279  public Evidence Evidence
280  {
281  [SecuritySafeCritical]
283  get
284  {
285  return EvidenceNoDemand;
286  }
287  }
288 
289  internal Evidence EvidenceNoDemand
290  {
291  [SecurityCritical]
292  get
293  {
294  if (_SecurityIdentity == null)
295  {
296  if (!IsDefaultAppDomain() && nIsDefaultAppDomainForEvidence())
297  {
298  return GetDefaultDomain().Evidence;
299  }
300  return new Evidence(new AppDomainEvidenceFactory(this));
301  }
302  return _SecurityIdentity.Clone();
303  }
304  }
305 
306  internal Evidence InternalEvidence => _SecurityIdentity;
307 
311  public string FriendlyName
312  {
313  [SecuritySafeCritical]
314  get
315  {
316  return nGetFriendlyName();
317  }
318  }
319 
323  public string BaseDirectory => FusionStore.ApplicationBase;
324 
328  public string RelativeSearchPath => FusionStore.PrivateBinPath;
329 
334  public bool ShadowCopyFiles
335  {
336  get
337  {
338  string shadowCopyFiles = FusionStore.ShadowCopyFiles;
339  if (shadowCopyFiles != null && string.Compare(shadowCopyFiles, "true", StringComparison.OrdinalIgnoreCase) == 0)
340  {
341  return true;
342  }
343  return false;
344  }
345  }
346 
350  {
351  [SecurityCritical]
352  get
353  {
354  return _activationContext;
355  }
356  }
357 
361  {
362  [SecurityCritical]
363  get
364  {
365  return _applicationIdentity;
366  }
367  }
368 
372  {
373  [SecurityCritical]
374  get
375  {
376  if (_applicationTrust == null && _IsFastFullTrustDomain)
377  {
378  _applicationTrust = new ApplicationTrust(new PermissionSet(PermissionState.Unrestricted));
379  }
380  return _applicationTrust;
381  }
382  }
383 
387  public string DynamicDirectory
388  {
389  [SecuritySafeCritical]
390  get
391  {
392  string dynamicDir = GetDynamicDir();
393  if (dynamicDir != null)
394  {
395  FileIOPermission.QuickDemand(FileIOPermissionAccess.PathDiscovery, dynamicDir);
396  }
397  return dynamicDir;
398  }
399  }
400 
401  internal DomainSpecificRemotingData RemotingData
402  {
403  get
404  {
405  if (_RemotingData == null)
406  {
407  CreateRemotingData();
408  }
409  return _RemotingData;
410  }
411  }
412 
413  internal AppDomainSetup FusionStore => _FusionStore;
414 
415  private Dictionary<string, object[]> LocalStore
416  {
417  get
418  {
419  if (_LocalStore != null)
420  {
421  return _LocalStore;
422  }
423  _LocalStore = new Dictionary<string, object[]>();
424  return _LocalStore;
425  }
426  }
427 
431  public AppDomainSetup SetupInformation => new AppDomainSetup(FusionStore, copyDomainBoundData: true);
432 
436  {
437  [SecurityCritical]
438  get
439  {
440  PermissionSet o = null;
441  GetGrantSet(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref o));
442  if (o != null)
443  {
444  return o.Copy();
445  }
446  return new PermissionSet(PermissionState.Unrestricted);
447  }
448  }
449 
453  public bool IsFullyTrusted
454  {
455  [SecuritySafeCritical]
456  get
457  {
458  PermissionSet o = null;
459  GetGrantSet(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref o));
460  return o?.IsUnrestricted() ?? true;
461  }
462  }
463 
467  public bool IsHomogenous
468  {
469  get
470  {
471  if (!_IsFastFullTrustDomain)
472  {
473  return _applicationTrust != null;
474  }
475  return true;
476  }
477  }
478 
479  internal bool IsLegacyCasPolicyEnabled
480  {
481  [SecuritySafeCritical]
482  get
483  {
484  return GetIsLegacyCasPolicyEnabled(GetNativeHandle());
485  }
486  }
487 
490  public int Id
491  {
492  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
493  get
494  {
495  return GetId();
496  }
497  }
498 
503  public static bool MonitoringIsEnabled
504  {
505  [SecurityCritical]
506  get
507  {
508  return nMonitoringIsEnabled();
509  }
510  [SecurityCritical]
511  set
512  {
513  if (!value)
514  {
515  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeTrue"));
516  }
517  nEnableMonitoring();
518  }
519  }
520 
525  {
526  [SecurityCritical]
527  get
528  {
529  long num = nGetTotalProcessorTime();
530  if (num == -1)
531  {
532  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WithoutARM"));
533  }
534  return new TimeSpan(num);
535  }
536  }
537 
542  {
543  [SecurityCritical]
544  get
545  {
546  long num = nGetTotalAllocatedMemorySize();
547  if (num == -1)
548  {
549  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WithoutARM"));
550  }
551  return num;
552  }
553  }
554 
559  public long MonitoringSurvivedMemorySize
560  {
561  [SecurityCritical]
562  get
563  {
564  long num = nGetLastSurvivedMemorySize();
565  if (num == -1)
566  {
567  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WithoutARM"));
568  }
569  return num;
570  }
571  }
572 
576  public static long MonitoringSurvivedProcessMemorySize
577  {
578  [SecurityCritical]
579  get
580  {
581  long num = nGetLastSurvivedProcessMemorySize();
582  if (num == -1)
583  {
584  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WithoutARM"));
585  }
586  return num;
587  }
588  }
589 
591  [method: SecurityCritical]
593 
595  public event ResolveEventHandler TypeResolve
596  {
597  [SecurityCritical]
598  add
599  {
600  lock (this)
601  {
602  _TypeResolve = (ResolveEventHandler)Delegate.Combine(_TypeResolve, value);
603  }
604  }
605  [SecurityCritical]
606  remove
607  {
608  lock (this)
609  {
610  _TypeResolve = (ResolveEventHandler)Delegate.Remove(_TypeResolve, value);
611  }
612  }
613  }
614 
617  {
618  [SecurityCritical]
619  add
620  {
621  lock (this)
622  {
623  _ResourceResolve = (ResolveEventHandler)Delegate.Combine(_ResourceResolve, value);
624  }
625  }
626  [SecurityCritical]
627  remove
628  {
629  lock (this)
630  {
631  _ResourceResolve = (ResolveEventHandler)Delegate.Remove(_ResourceResolve, value);
632  }
633  }
634  }
635 
638  {
639  [SecurityCritical]
640  add
641  {
642  lock (this)
643  {
644  _AssemblyResolve = (ResolveEventHandler)Delegate.Combine(_AssemblyResolve, value);
645  }
646  }
647  [SecurityCritical]
648  remove
649  {
650  lock (this)
651  {
652  _AssemblyResolve = (ResolveEventHandler)Delegate.Remove(_AssemblyResolve, value);
653  }
654  }
655  }
656 
658  [method: SecurityCritical]
660 
662  public event EventHandler ProcessExit
663  {
664  [SecuritySafeCritical]
665  add
666  {
667  if (value != null)
668  {
670  lock (this)
671  {
672  _processExit = (EventHandler)Delegate.Combine(_processExit, value);
673  }
674  }
675  }
676  remove
677  {
678  lock (this)
679  {
680  _processExit = (EventHandler)Delegate.Remove(_processExit, value);
681  }
682  }
683  }
684 
686  public event EventHandler DomainUnload
687  {
688  [SecuritySafeCritical]
689  add
690  {
691  if (value != null)
692  {
694  lock (this)
695  {
696  _domainUnload = (EventHandler)Delegate.Combine(_domainUnload, value);
697  }
698  }
699  }
700  remove
701  {
702  lock (this)
703  {
704  _domainUnload = (EventHandler)Delegate.Remove(_domainUnload, value);
705  }
706  }
707  }
708 
711  {
712  [SecurityCritical]
713  add
714  {
715  if (value != null)
716  {
718  lock (this)
719  {
720  _unhandledException = (UnhandledExceptionEventHandler)Delegate.Combine(_unhandledException, value);
721  }
722  }
723  }
724  [SecurityCritical]
725  remove
726  {
727  lock (this)
728  {
729  _unhandledException = (UnhandledExceptionEventHandler)Delegate.Remove(_unhandledException, value);
730  }
731  }
732  }
733 
735  public event EventHandler<FirstChanceExceptionEventArgs> FirstChanceException
736  {
737  [SecurityCritical]
738  add
739  {
740  if (value != null)
741  {
743  lock (this)
744  {
745  _firstChanceException = (EventHandler<FirstChanceExceptionEventArgs>)Delegate.Combine(_firstChanceException, value);
746  }
747  }
748  }
749  [SecurityCritical]
750  remove
751  {
752  lock (this)
753  {
754  _firstChanceException = (EventHandler<FirstChanceExceptionEventArgs>)Delegate.Remove(_firstChanceException, value);
755  }
756  }
757  }
758 
759  [DllImport("QCall", CharSet = CharSet.Unicode)]
760  [SecurityCritical]
761  [SuppressUnmanagedCodeSecurity]
762  [return: MarshalAs(UnmanagedType.Bool)]
763  private static extern bool DisableFusionUpdatesFromADManager(AppDomainHandle domain);
764 
765  [DllImport("QCall", CharSet = CharSet.Unicode)]
766  [SecurityCritical]
767  [SuppressUnmanagedCodeSecurity]
768  [return: MarshalAs(UnmanagedType.I4)]
769  private static extern APPX_FLAGS nGetAppXFlags();
770 
771  [DllImport("QCall", CharSet = CharSet.Unicode)]
772  [SecurityCritical]
773  [SuppressUnmanagedCodeSecurity]
774  private static extern void GetAppDomainManagerType(AppDomainHandle domain, StringHandleOnStack retAssembly, StringHandleOnStack retType);
775 
776  [DllImport("QCall", CharSet = CharSet.Unicode)]
777  [SecurityCritical]
778  [SuppressUnmanagedCodeSecurity]
779  private static extern void SetAppDomainManagerType(AppDomainHandle domain, string assembly, string type);
780 
781  [MethodImpl(MethodImplOptions.InternalCall)]
782  [SecurityCritical]
783  private static extern void nSetHostSecurityManagerFlags(HostSecurityManagerOptions flags);
784 
785  [DllImport("QCall", CharSet = CharSet.Unicode)]
786  [SecurityCritical]
787  [SuppressUnmanagedCodeSecurity]
788  private static extern void SetSecurityHomogeneousFlag(AppDomainHandle domain, [MarshalAs(UnmanagedType.Bool)] bool runtimeSuppliedHomogenousGrantSet);
789 
790  [DllImport("QCall", CharSet = CharSet.Unicode)]
791  [SecurityCritical]
792  [SuppressUnmanagedCodeSecurity]
793  private static extern void SetLegacyCasPolicyEnabled(AppDomainHandle domain);
794 
795  [SecurityCritical]
796  private void SetLegacyCasPolicyEnabled()
797  {
798  SetLegacyCasPolicyEnabled(GetNativeHandle());
799  }
800 
801  internal AppDomainHandle GetNativeHandle()
802  {
803  if (_pDomain.IsNull())
804  {
805  throw new InvalidOperationException(Environment.GetResourceString("Argument_InvalidHandle"));
806  }
807  return new AppDomainHandle(_pDomain);
808  }
809 
810  [SecuritySafeCritical]
811  private void CreateAppDomainManager()
812  {
813  AppDomainSetup fusionStore = FusionStore;
814  GetAppDomainManagerType(out string assembly, out string type);
815  if (assembly != null && type != null)
816  {
817  try
818  {
819  new PermissionSet(PermissionState.Unrestricted).Assert();
820  _domainManager = (CreateInstanceAndUnwrap(assembly, type) as AppDomainManager);
822  }
823  catch (FileNotFoundException inner)
824  {
825  throw new TypeLoadException(Environment.GetResourceString("Argument_NoDomainManager"), inner);
826  }
827  catch (SecurityException inner2)
828  {
829  throw new TypeLoadException(Environment.GetResourceString("Argument_NoDomainManager"), inner2);
830  }
831  catch (TypeLoadException inner3)
832  {
833  throw new TypeLoadException(Environment.GetResourceString("Argument_NoDomainManager"), inner3);
834  }
835  if (_domainManager == null)
836  {
837  throw new TypeLoadException(Environment.GetResourceString("Argument_NoDomainManager"));
838  }
839  FusionStore.AppDomainManagerAssembly = assembly;
840  FusionStore.AppDomainManagerType = type;
841  bool flag = _domainManager.GetType() != typeof(AppDomainManager) && !DisableFusionUpdatesFromADManager();
842  AppDomainSetup oldInfo = null;
843  if (flag)
844  {
845  oldInfo = new AppDomainSetup(FusionStore, copyDomainBoundData: true);
846  }
847  _domainManager.InitializeNewDomain(FusionStore);
848  if (flag)
849  {
850  SetupFusionStore(_FusionStore, oldInfo);
851  }
852  AppDomainManagerInitializationOptions initializationFlags = _domainManager.InitializationFlags;
853  if ((initializationFlags & AppDomainManagerInitializationOptions.RegisterWithHost) == AppDomainManagerInitializationOptions.RegisterWithHost)
854  {
855  _domainManager.RegisterWithHost();
856  }
857  }
858  InitializeCompatibilityFlags();
859  }
860 
861  private void InitializeCompatibilityFlags()
862  {
863  AppDomainSetup fusionStore = FusionStore;
864  if (fusionStore.GetCompatibilityFlags() != null)
865  {
866  _compatFlags = new Dictionary<string, object>(fusionStore.GetCompatibilityFlags(), StringComparer.OrdinalIgnoreCase);
867  }
868  _compatFlagsInitialized = true;
869  CompatibilitySwitches.InitializeSwitches();
870  }
871 
872  [SecuritySafeCritical]
873  internal string GetTargetFrameworkName()
874  {
875  string text = _FusionStore.TargetFrameworkName;
876  if (text == null && IsDefaultAppDomain() && !_FusionStore.CheckedForTargetFrameworkName)
877  {
878  Assembly entryAssembly = Assembly.GetEntryAssembly();
879  if (entryAssembly != null)
880  {
882  if (array != null && array.Length != 0)
883  {
884  text = array[0].FrameworkName;
885  _FusionStore.TargetFrameworkName = text;
886  }
887  }
888  _FusionStore.CheckedForTargetFrameworkName = true;
889  }
890  return text;
891  }
892 
893  [SecuritySafeCritical]
894  private void SetTargetFrameworkName(string targetFrameworkName)
895  {
896  if (!_FusionStore.CheckedForTargetFrameworkName)
897  {
898  _FusionStore.TargetFrameworkName = targetFrameworkName;
899  _FusionStore.CheckedForTargetFrameworkName = true;
900  }
901  }
902 
903  [SecuritySafeCritical]
904  internal bool DisableFusionUpdatesFromADManager()
905  {
906  return DisableFusionUpdatesFromADManager(GetNativeHandle());
907  }
908 
909  [SecuritySafeCritical]
910  internal static bool IsAppXModel()
911  {
912  return (Flags & APPX_FLAGS.APPX_FLAGS_APPX_MODEL) != (APPX_FLAGS)0;
913  }
914 
915  [SecuritySafeCritical]
916  internal static bool IsAppXDesignMode()
917  {
918  return (Flags & APPX_FLAGS.APPX_FLAGS_APPX_MASK) == (APPX_FLAGS.APPX_FLAGS_APPX_MODEL | APPX_FLAGS.APPX_FLAGS_APPX_DESIGN_MODE);
919  }
920 
921  [SecuritySafeCritical]
922  internal static void CheckLoadFromSupported()
923  {
924  if (IsAppXModel())
925  {
926  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AppX", "Assembly.LoadFrom"));
927  }
928  }
929 
930  [SecuritySafeCritical]
931  internal static void CheckLoadFileSupported()
932  {
933  if (IsAppXModel())
934  {
935  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AppX", "Assembly.LoadFile"));
936  }
937  }
938 
939  [SecuritySafeCritical]
940  internal static void CheckReflectionOnlyLoadSupported()
941  {
942  if (IsAppXModel())
943  {
944  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AppX", "Assembly.ReflectionOnlyLoad"));
945  }
946  }
947 
948  [SecuritySafeCritical]
949  internal static void CheckLoadWithPartialNameSupported(StackCrawlMark stackMark)
950  {
951  if (IsAppXModel())
952  {
953  RuntimeAssembly executingAssembly = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
954  if (!(executingAssembly != null) || !executingAssembly.IsFrameworkAssembly())
955  {
956  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AppX", "Assembly.LoadWithPartialName"));
957  }
958  }
959  }
960 
961  [SecuritySafeCritical]
962  internal static void CheckDefinePInvokeSupported()
963  {
964  if (IsAppXModel())
965  {
966  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AppX", "DefinePInvokeMethod"));
967  }
968  }
969 
970  [SecuritySafeCritical]
971  internal static void CheckLoadByteArraySupported()
972  {
973  if (IsAppXModel())
974  {
975  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AppX", "Assembly.Load(byte[], ...)"));
976  }
977  }
978 
979  [SecuritySafeCritical]
980  internal static void CheckCreateDomainSupported()
981  {
982  if (IsAppXModel() && !IsAppXDesignMode())
983  {
984  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AppX", "AppDomain.CreateDomain"));
985  }
986  }
987 
988  [SecuritySafeCritical]
989  internal void GetAppDomainManagerType(out string assembly, out string type)
990  {
991  string s = null;
992  string s2 = null;
993  GetAppDomainManagerType(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref s), JitHelpers.GetStringHandleOnStack(ref s2));
994  assembly = s;
995  type = s2;
996  }
997 
998  [SecuritySafeCritical]
999  private void SetAppDomainManagerType(string assembly, string type)
1000  {
1001  SetAppDomainManagerType(GetNativeHandle(), assembly, type);
1002  }
1003 
1004  [DllImport("QCall", CharSet = CharSet.Unicode)]
1005  [SecurityCritical]
1006  [SuppressUnmanagedCodeSecurity]
1007  private static extern void SetCanonicalConditionalAptcaList(AppDomainHandle appDomain, string canonicalList);
1008 
1009  [SecurityCritical]
1010  private void SetCanonicalConditionalAptcaList(string canonicalList)
1011  {
1012  SetCanonicalConditionalAptcaList(GetNativeHandle(), canonicalList);
1013  }
1014 
1015  private void SetupDefaultClickOnceDomain(string fullName, string[] manifestPaths, string[] activationData)
1016  {
1017  FusionStore.ActivationArguments = new ActivationArguments(fullName, manifestPaths, activationData);
1018  }
1019 
1020  [SecurityCritical]
1021  private void InitializeDomainSecurity(Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, bool generateDefaultEvidence, IntPtr parentSecurityDescriptor, bool publishAppDomain)
1022  {
1023  AppDomainSetup fusionStore = FusionStore;
1024  if (CompatibilitySwitches.IsNetFx40LegacySecurityPolicy)
1025  {
1026  SetLegacyCasPolicyEnabled();
1027  }
1028  if (fusionStore.ActivationArguments != null)
1029  {
1030  ActivationContext activationContext = null;
1031  ApplicationIdentity applicationIdentity = null;
1032  string[] array = null;
1033  CmsUtils.CreateActivationContext(fusionStore.ActivationArguments.ApplicationFullName, fusionStore.ActivationArguments.ApplicationManifestPaths, fusionStore.ActivationArguments.UseFusionActivationContext, out applicationIdentity, out activationContext);
1034  array = fusionStore.ActivationArguments.ActivationData;
1035  providedSecurityInfo = CmsUtils.MergeApplicationEvidence(providedSecurityInfo, applicationIdentity, activationContext, array, fusionStore.ApplicationTrust);
1036  SetupApplicationHelper(providedSecurityInfo, creatorsSecurityInfo, applicationIdentity, activationContext, array);
1037  }
1038  else
1039  {
1040  bool runtimeSuppliedHomogenousGrantSet = false;
1041  ApplicationTrust applicationTrust = fusionStore.ApplicationTrust;
1042  if (applicationTrust == null && !IsLegacyCasPolicyEnabled)
1043  {
1044  _IsFastFullTrustDomain = true;
1045  runtimeSuppliedHomogenousGrantSet = true;
1046  }
1047  if (applicationTrust != null)
1048  {
1049  SetupDomainSecurityForHomogeneousDomain(applicationTrust, runtimeSuppliedHomogenousGrantSet);
1050  }
1051  else if (_IsFastFullTrustDomain)
1052  {
1053  SetSecurityHomogeneousFlag(GetNativeHandle(), runtimeSuppliedHomogenousGrantSet);
1054  }
1055  }
1056  Evidence evidence = (providedSecurityInfo != null) ? providedSecurityInfo : creatorsSecurityInfo;
1057  if (evidence == null && generateDefaultEvidence)
1058  {
1059  evidence = new Evidence(new AppDomainEvidenceFactory(this));
1060  }
1061  if (_domainManager != null)
1062  {
1063  HostSecurityManager hostSecurityManager = _domainManager.HostSecurityManager;
1064  if (hostSecurityManager != null)
1065  {
1066  nSetHostSecurityManagerFlags(hostSecurityManager.Flags);
1067  if ((hostSecurityManager.Flags & HostSecurityManagerOptions.HostAppDomainEvidence) == HostSecurityManagerOptions.HostAppDomainEvidence)
1068  {
1069  evidence = hostSecurityManager.ProvideAppDomainEvidence(evidence);
1070  if (evidence != null && evidence.Target == null)
1071  {
1072  evidence.Target = new AppDomainEvidenceFactory(this);
1073  }
1074  }
1075  }
1076  }
1077  _SecurityIdentity = evidence;
1078  SetupDomainSecurity(evidence, parentSecurityDescriptor, publishAppDomain);
1079  if (_domainManager != null)
1080  {
1081  RunDomainManagerPostInitialization(_domainManager);
1082  }
1083  }
1084 
1085  [SecurityCritical]
1086  private void RunDomainManagerPostInitialization(AppDomainManager domainManager)
1087  {
1088  HostExecutionContextManager hostExecutionContextManager = domainManager.HostExecutionContextManager;
1089  if (!IsLegacyCasPolicyEnabled)
1090  {
1091  return;
1092  }
1093  HostSecurityManager hostSecurityManager = domainManager.HostSecurityManager;
1094  if (hostSecurityManager != null && (hostSecurityManager.Flags & HostSecurityManagerOptions.HostPolicyLevel) == HostSecurityManagerOptions.HostPolicyLevel)
1095  {
1096  PolicyLevel domainPolicy = hostSecurityManager.DomainPolicy;
1097  if (domainPolicy != null)
1098  {
1099  SetAppDomainPolicy(domainPolicy);
1100  }
1101  }
1102  }
1103 
1104  [SecurityCritical]
1105  private void SetupApplicationHelper(Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, ApplicationIdentity appIdentity, ActivationContext activationContext, string[] activationData)
1106  {
1107  HostSecurityManager hostSecurityManager = CurrentDomain.HostSecurityManager;
1108  ApplicationTrust applicationTrust = hostSecurityManager.DetermineApplicationTrust(providedSecurityInfo, creatorsSecurityInfo, new TrustManagerContext());
1109  if (applicationTrust == null || !applicationTrust.IsApplicationTrustedToRun)
1110  {
1111  throw new PolicyException(Environment.GetResourceString("Policy_NoExecutionPermission"), -2146233320, null);
1112  }
1113  if (activationContext != null)
1114  {
1115  SetupDomainForApplication(activationContext, activationData);
1116  }
1117  SetupDomainSecurityForApplication(appIdentity, applicationTrust);
1118  }
1119 
1120  [SecurityCritical]
1121  private void SetupDomainForApplication(ActivationContext activationContext, string[] activationData)
1122  {
1123  if (IsDefaultAppDomain())
1124  {
1125  AppDomainSetup fusionStore = FusionStore;
1126  fusionStore.ActivationArguments = new ActivationArguments(activationContext, activationData);
1127  string entryPointFullPath = CmsUtils.GetEntryPointFullPath(activationContext);
1128  if (!string.IsNullOrEmpty(entryPointFullPath))
1129  {
1130  fusionStore.SetupDefaults(entryPointFullPath);
1131  }
1132  else
1133  {
1134  fusionStore.ApplicationBase = activationContext.ApplicationDirectory;
1135  }
1136  SetupFusionStore(fusionStore, null);
1137  }
1138  activationContext.PrepareForExecution();
1139  activationContext.SetApplicationState(ActivationContext.ApplicationState.Starting);
1140  activationContext.SetApplicationState(ActivationContext.ApplicationState.Running);
1141  IPermission permission = null;
1142  string dataDirectory = activationContext.DataDirectory;
1143  if (dataDirectory != null && dataDirectory.Length > 0)
1144  {
1145  permission = new FileIOPermission(FileIOPermissionAccess.PathDiscovery, dataDirectory);
1146  }
1147  SetData("DataDirectory", dataDirectory, permission);
1148  _activationContext = activationContext;
1149  }
1150 
1151  [SecurityCritical]
1152  private void SetupDomainSecurityForApplication(ApplicationIdentity appIdentity, ApplicationTrust appTrust)
1153  {
1154  _applicationIdentity = appIdentity;
1155  SetupDomainSecurityForHomogeneousDomain(appTrust, runtimeSuppliedHomogenousGrantSet: false);
1156  }
1157 
1158  [SecurityCritical]
1159  private void SetupDomainSecurityForHomogeneousDomain(ApplicationTrust appTrust, bool runtimeSuppliedHomogenousGrantSet)
1160  {
1161  if (runtimeSuppliedHomogenousGrantSet)
1162  {
1163  _FusionStore.ApplicationTrust = null;
1164  }
1165  _applicationTrust = appTrust;
1166  SetSecurityHomogeneousFlag(GetNativeHandle(), runtimeSuppliedHomogenousGrantSet);
1167  }
1168 
1169  [SecuritySafeCritical]
1170  private int ActivateApplication()
1171  {
1172  ObjectHandle objectHandle = Activator.CreateInstance(CurrentDomain.ActivationContext);
1173  return (int)objectHandle.Unwrap();
1174  }
1175 
1176  private Assembly ResolveAssemblyForIntrospection(object sender, ResolveEventArgs args)
1177  {
1178  return Assembly.ReflectionOnlyLoad(ApplyPolicy(args.Name));
1179  }
1180 
1181  [SecuritySafeCritical]
1182  private void EnableResolveAssembliesForIntrospection(string verifiedFileDirectory)
1183  {
1184  CurrentDomain.ReflectionOnlyAssemblyResolve += ResolveAssemblyForIntrospection;
1185  string[] packageGraphFilePaths = null;
1186  if (verifiedFileDirectory != null)
1187  {
1188  packageGraphFilePaths = new string[1]
1189  {
1190  verifiedFileDirectory
1191  };
1192  }
1193  NamespaceResolverForIntrospection @object = new NamespaceResolverForIntrospection(packageGraphFilePaths);
1194  WindowsRuntimeMetadata.ReflectionOnlyNamespaceResolve += @object.ResolveNamespace;
1195  }
1196 
1205  [MethodImpl(MethodImplOptions.NoInlining)]
1206  [SecuritySafeCritical]
1208  {
1209  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1210  return InternalDefineDynamicAssembly(name, access, null, null, null, null, null, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1211  }
1212 
1222  [MethodImpl(MethodImplOptions.NoInlining)]
1223  [SecuritySafeCritical]
1225  {
1226  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1227  return InternalDefineDynamicAssembly(name, access, null, null, null, null, null, ref stackMark, assemblyAttributes, SecurityContextSource.CurrentAssembly);
1228  }
1229 
1242  [MethodImpl(MethodImplOptions.NoInlining)]
1243  [SecuritySafeCritical]
1245  {
1246  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1247  return InternalDefineDynamicAssembly(name, access, null, null, null, null, null, ref stackMark, assemblyAttributes, securityContextSource);
1248  }
1249 
1259  [MethodImpl(MethodImplOptions.NoInlining)]
1260  [SecuritySafeCritical]
1262  {
1263  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1264  return InternalDefineDynamicAssembly(name, access, dir, null, null, null, null, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1265  }
1266 
1276  [MethodImpl(MethodImplOptions.NoInlining)]
1277  [SecuritySafeCritical]
1278  [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1280  {
1281  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1282  return InternalDefineDynamicAssembly(name, access, null, evidence, null, null, null, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1283  }
1284 
1296  [MethodImpl(MethodImplOptions.NoInlining)]
1297  [SecuritySafeCritical]
1298  [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1299  public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
1300  {
1301  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1302  return InternalDefineDynamicAssembly(name, access, null, null, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1303  }
1304 
1315  [MethodImpl(MethodImplOptions.NoInlining)]
1316  [SecuritySafeCritical]
1317  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of DefineDynamicAssembly which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")]
1319  {
1320  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1321  return InternalDefineDynamicAssembly(name, access, dir, evidence, null, null, null, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1322  }
1323 
1336  [MethodImpl(MethodImplOptions.NoInlining)]
1337  [SecuritySafeCritical]
1338  [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1339  public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
1340  {
1341  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1342  return InternalDefineDynamicAssembly(name, access, dir, null, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1343  }
1344 
1357  [MethodImpl(MethodImplOptions.NoInlining)]
1358  [SecuritySafeCritical]
1359  [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1360  public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
1361  {
1362  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1363  return InternalDefineDynamicAssembly(name, access, null, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1364  }
1365 
1379  [MethodImpl(MethodImplOptions.NoInlining)]
1380  [SecuritySafeCritical]
1381  [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. Please see http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")]
1382  public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
1383  {
1384  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1385  return InternalDefineDynamicAssembly(name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1386  }
1387 
1403  [MethodImpl(MethodImplOptions.NoInlining)]
1404  [SecuritySafeCritical]
1405  [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1406  public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, bool isSynchronized)
1407  {
1408  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1409  return InternalDefineDynamicAssembly(name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, null, SecurityContextSource.CurrentAssembly);
1410  }
1411 
1428  [MethodImpl(MethodImplOptions.NoInlining)]
1429  [SecuritySafeCritical]
1430  [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1431  public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
1432  {
1433  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1434  return InternalDefineDynamicAssembly(name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, assemblyAttributes, SecurityContextSource.CurrentAssembly);
1435  }
1436 
1449  [MethodImpl(MethodImplOptions.NoInlining)]
1450  [SecuritySafeCritical]
1451  public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
1452  {
1453  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1454  return InternalDefineDynamicAssembly(name, access, dir, null, null, null, null, ref stackMark, assemblyAttributes, SecurityContextSource.CurrentAssembly);
1455  }
1456 
1457  [MethodImpl(MethodImplOptions.NoInlining)]
1458  [SecurityCritical]
1459  private AssemblyBuilder InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable<CustomAttributeBuilder> assemblyAttributes, SecurityContextSource securityContextSource)
1460  {
1461  return AssemblyBuilder.InternalDefineDynamicAssembly(name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, assemblyAttributes, securityContextSource);
1462  }
1463 
1464  [MethodImpl(MethodImplOptions.InternalCall)]
1465  [SecuritySafeCritical]
1466  private extern string nApplyPolicy(AssemblyName an);
1467 
1471  [ComVisible(false)]
1472  public string ApplyPolicy(string assemblyName)
1473  {
1474  AssemblyName assemblyName2 = new AssemblyName(assemblyName);
1475  byte[] array = assemblyName2.GetPublicKeyToken();
1476  if (array == null)
1477  {
1478  array = assemblyName2.GetPublicKey();
1479  }
1480  if (array == null || array.Length == 0)
1481  {
1482  return assemblyName;
1483  }
1484  return nApplyPolicy(assemblyName2);
1485  }
1486 
1504  public ObjectHandle CreateInstance(string assemblyName, string typeName)
1505  {
1506  if (this == null)
1507  {
1508  throw new NullReferenceException();
1509  }
1510  if (assemblyName == null)
1511  {
1512  throw new ArgumentNullException("assemblyName");
1513  }
1514  return Activator.CreateInstance(assemblyName, typeName);
1515  }
1516 
1517  [SecurityCritical]
1518  internal ObjectHandle InternalCreateInstanceWithNoSecurity(string assemblyName, string typeName)
1519  {
1520  PermissionSet.s_fullTrust.Assert();
1521  return CreateInstance(assemblyName, typeName);
1522  }
1523 
1542  public ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName)
1543  {
1544  if (this == null)
1545  {
1546  throw new NullReferenceException();
1547  }
1548  return Activator.CreateInstanceFrom(assemblyFile, typeName);
1549  }
1550 
1551  [SecurityCritical]
1552  internal ObjectHandle InternalCreateInstanceFromWithNoSecurity(string assemblyName, string typeName)
1553  {
1554  PermissionSet.s_fullTrust.Assert();
1555  return CreateInstanceFrom(assemblyName, typeName);
1556  }
1557 
1578  public ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName)
1579  {
1580  if (this == null)
1581  {
1582  throw new NullReferenceException();
1583  }
1584  return Activator.CreateComInstanceFrom(assemblyName, typeName);
1585  }
1586 
1609  public ObjectHandle CreateComInstanceFrom(string assemblyFile, string typeName, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
1610  {
1611  if (this == null)
1612  {
1613  throw new NullReferenceException();
1614  }
1615  return Activator.CreateComInstanceFrom(assemblyFile, typeName, hashValue, hashAlgorithm);
1616  }
1617 
1637  public ObjectHandle CreateInstance(string assemblyName, string typeName, object[] activationAttributes)
1638  {
1639  if (this == null)
1640  {
1641  throw new NullReferenceException();
1642  }
1643  if (assemblyName == null)
1644  {
1645  throw new ArgumentNullException("assemblyName");
1646  }
1647  return Activator.CreateInstance(assemblyName, typeName, activationAttributes);
1648  }
1649 
1669  public ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, object[] activationAttributes)
1670  {
1671  if (this == null)
1672  {
1673  throw new NullReferenceException();
1674  }
1675  return Activator.CreateInstanceFrom(assemblyFile, typeName, activationAttributes);
1676  }
1677 
1704  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstance which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1705  public ObjectHandle CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
1706  {
1707  if (this == null)
1708  {
1709  throw new NullReferenceException();
1710  }
1711  if (assemblyName == null)
1712  {
1713  throw new ArgumentNullException("assemblyName");
1714  }
1715  if (securityAttributes != null && !IsLegacyCasPolicyEnabled)
1716  {
1717  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
1718  }
1719  return Activator.CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes);
1720  }
1721 
1747  public ObjectHandle CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
1748  {
1749  if (this == null)
1750  {
1751  throw new NullReferenceException();
1752  }
1753  if (assemblyName == null)
1754  {
1755  throw new ArgumentNullException("assemblyName");
1756  }
1757  return Activator.CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes);
1758  }
1759 
1760  [SecurityCritical]
1761  internal ObjectHandle InternalCreateInstanceWithNoSecurity(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
1762  {
1763  PermissionSet.s_fullTrust.Assert();
1764  return CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes);
1765  }
1766 
1794  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1795  public ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
1796  {
1797  if (this == null)
1798  {
1799  throw new NullReferenceException();
1800  }
1801  if (securityAttributes != null && !IsLegacyCasPolicyEnabled)
1802  {
1803  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
1804  }
1805  return Activator.CreateInstanceFrom(assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes);
1806  }
1807 
1834  public ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
1835  {
1836  if (this == null)
1837  {
1838  throw new NullReferenceException();
1839  }
1840  return Activator.CreateInstanceFrom(assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes);
1841  }
1842 
1843  [SecurityCritical]
1844  internal ObjectHandle InternalCreateInstanceFromWithNoSecurity(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
1845  {
1846  PermissionSet.s_fullTrust.Assert();
1847  return CreateInstanceFrom(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes);
1848  }
1849 
1861  [MethodImpl(MethodImplOptions.NoInlining)]
1862  [SecuritySafeCritical]
1863  public Assembly Load(AssemblyName assemblyRef)
1864  {
1865  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1866  return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, null, null, ref stackMark, throwOnFileNotFound: true, forIntrospection: false, suppressSecurityChecks: false);
1867  }
1868 
1880  [MethodImpl(MethodImplOptions.NoInlining)]
1881  [SecuritySafeCritical]
1882  public Assembly Load(string assemblyString)
1883  {
1884  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1885  return RuntimeAssembly.InternalLoad(assemblyString, null, ref stackMark, forIntrospection: false);
1886  }
1887 
1897  [MethodImpl(MethodImplOptions.NoInlining)]
1898  [SecuritySafeCritical]
1899  public Assembly Load(byte[] rawAssembly)
1900  {
1901  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1902  return RuntimeAssembly.nLoadImage(rawAssembly, null, null, ref stackMark, fIntrospection: false, SecurityContextSource.CurrentAssembly);
1903  }
1904 
1915  [MethodImpl(MethodImplOptions.NoInlining)]
1916  [SecuritySafeCritical]
1917  public Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore)
1918  {
1919  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1920  return RuntimeAssembly.nLoadImage(rawAssembly, rawSymbolStore, null, ref stackMark, fIntrospection: false, SecurityContextSource.CurrentAssembly);
1921  }
1922 
1936  [MethodImpl(MethodImplOptions.NoInlining)]
1937  [SecuritySafeCritical]
1938  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")]
1939  [SecurityPermission(SecurityAction.Demand, ControlEvidence = true)]
1940  public Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
1941  {
1942  if (securityEvidence != null && !IsLegacyCasPolicyEnabled)
1943  {
1944  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
1945  }
1946  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1947  return RuntimeAssembly.nLoadImage(rawAssembly, rawSymbolStore, securityEvidence, ref stackMark, fIntrospection: false, SecurityContextSource.CurrentAssembly);
1948  }
1949 
1962  [MethodImpl(MethodImplOptions.NoInlining)]
1963  [SecuritySafeCritical]
1964  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1965  public Assembly Load(AssemblyName assemblyRef, Evidence assemblySecurity)
1966  {
1967  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1968  return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, assemblySecurity, null, ref stackMark, throwOnFileNotFound: true, forIntrospection: false, suppressSecurityChecks: false);
1969  }
1970 
1983  [MethodImpl(MethodImplOptions.NoInlining)]
1984  [SecuritySafeCritical]
1985  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
1986  public Assembly Load(string assemblyString, Evidence assemblySecurity)
1987  {
1988  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1989  return RuntimeAssembly.InternalLoad(assemblyString, assemblySecurity, ref stackMark, forIntrospection: false);
1990  }
1991 
2005  public int ExecuteAssembly(string assemblyFile)
2006  {
2007  return ExecuteAssembly(assemblyFile, (string[])null);
2008  }
2009 
2024  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of ExecuteAssembly which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
2025  public int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity)
2026  {
2027  return ExecuteAssembly(assemblyFile, assemblySecurity, null);
2028  }
2029 
2047  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of ExecuteAssembly which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
2048  public int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity, string[] args)
2049  {
2050  if (assemblySecurity != null && !IsLegacyCasPolicyEnabled)
2051  {
2052  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
2053  }
2054  RuntimeAssembly assembly = (RuntimeAssembly)Assembly.LoadFrom(assemblyFile, assemblySecurity);
2055  if (args == null)
2056  {
2057  args = new string[0];
2058  }
2059  return nExecuteAssembly(assembly, args);
2060  }
2061 
2077  public int ExecuteAssembly(string assemblyFile, string[] args)
2078  {
2079  RuntimeAssembly assembly = (RuntimeAssembly)Assembly.LoadFrom(assemblyFile);
2080  if (args == null)
2081  {
2082  args = new string[0];
2083  }
2084  return nExecuteAssembly(assembly, args);
2085  }
2086 
2106  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of ExecuteAssembly which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
2107  public int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
2108  {
2109  if (assemblySecurity != null && !IsLegacyCasPolicyEnabled)
2110  {
2111  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
2112  }
2113  RuntimeAssembly assembly = (RuntimeAssembly)Assembly.LoadFrom(assemblyFile, assemblySecurity, hashValue, hashAlgorithm);
2114  if (args == null)
2115  {
2116  args = new string[0];
2117  }
2118  return nExecuteAssembly(assembly, args);
2119  }
2120 
2138  public int ExecuteAssembly(string assemblyFile, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
2139  {
2140  RuntimeAssembly assembly = (RuntimeAssembly)Assembly.LoadFrom(assemblyFile, hashValue, hashAlgorithm);
2141  if (args == null)
2142  {
2143  args = new string[0];
2144  }
2145  return nExecuteAssembly(assembly, args);
2146  }
2147 
2159  public int ExecuteAssemblyByName(string assemblyName)
2160  {
2161  return ExecuteAssemblyByName(assemblyName, (string[])null);
2162  }
2163 
2176  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of ExecuteAssemblyByName which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
2177  public int ExecuteAssemblyByName(string assemblyName, Evidence assemblySecurity)
2178  {
2179  return ExecuteAssemblyByName(assemblyName, assemblySecurity, (string[])null);
2180  }
2181 
2197  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of ExecuteAssemblyByName which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
2198  public int ExecuteAssemblyByName(string assemblyName, Evidence assemblySecurity, params string[] args)
2199  {
2200  if (assemblySecurity != null && !IsLegacyCasPolicyEnabled)
2201  {
2202  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
2203  }
2204  RuntimeAssembly assembly = (RuntimeAssembly)Assembly.Load(assemblyName, assemblySecurity);
2205  if (args == null)
2206  {
2207  args = new string[0];
2208  }
2209  return nExecuteAssembly(assembly, args);
2210  }
2211 
2225  public int ExecuteAssemblyByName(string assemblyName, params string[] args)
2226  {
2227  RuntimeAssembly assembly = (RuntimeAssembly)Assembly.Load(assemblyName);
2228  if (args == null)
2229  {
2230  args = new string[0];
2231  }
2232  return nExecuteAssembly(assembly, args);
2233  }
2234 
2248  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of ExecuteAssemblyByName which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
2249  public int ExecuteAssemblyByName(AssemblyName assemblyName, Evidence assemblySecurity, params string[] args)
2250  {
2251  if (assemblySecurity != null && !IsLegacyCasPolicyEnabled)
2252  {
2253  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
2254  }
2255  RuntimeAssembly assembly = (RuntimeAssembly)Assembly.Load(assemblyName, assemblySecurity);
2256  if (args == null)
2257  {
2258  args = new string[0];
2259  }
2260  return nExecuteAssembly(assembly, args);
2261  }
2262 
2274  public int ExecuteAssemblyByName(AssemblyName assemblyName, params string[] args)
2275  {
2276  RuntimeAssembly assembly = (RuntimeAssembly)Assembly.Load(assemblyName);
2277  if (args == null)
2278  {
2279  args = new string[0];
2280  }
2281  return nExecuteAssembly(assembly, args);
2282  }
2283 
2284  internal EvidenceBase GetHostEvidence(Type type)
2285  {
2286  if (_SecurityIdentity != null)
2287  {
2288  return _SecurityIdentity.GetHostEvidence(type);
2289  }
2290  return new Evidence(new AppDomainEvidenceFactory(this)).GetHostEvidence(type);
2291  }
2292 
2296  [SecuritySafeCritical]
2297  public override string ToString()
2298  {
2299  StringBuilder stringBuilder = StringBuilderCache.Acquire();
2300  string text = nGetFriendlyName();
2301  if (text != null)
2302  {
2303  stringBuilder.Append(Environment.GetResourceString("Loader_Name") + text);
2304  stringBuilder.Append(Environment.NewLine);
2305  }
2306  if (_Policies == null || _Policies.Length == 0)
2307  {
2308  stringBuilder.Append(Environment.GetResourceString("Loader_NoContextPolicies") + Environment.NewLine);
2309  }
2310  else
2311  {
2312  stringBuilder.Append(Environment.GetResourceString("Loader_ContextPolicies") + Environment.NewLine);
2313  for (int i = 0; i < _Policies.Length; i++)
2314  {
2315  stringBuilder.Append(_Policies[i]);
2316  stringBuilder.Append(Environment.NewLine);
2317  }
2318  }
2319  return StringBuilderCache.GetStringAndRelease(stringBuilder);
2320  }
2321 
2326  {
2327  return nGetAssemblies(forIntrospection: false);
2328  }
2329 
2334  {
2335  return nGetAssemblies(forIntrospection: true);
2336  }
2337 
2338  [MethodImpl(MethodImplOptions.InternalCall)]
2339  [SecuritySafeCritical]
2340  private extern Assembly[] nGetAssemblies(bool forIntrospection);
2341 
2342  [MethodImpl(MethodImplOptions.InternalCall)]
2343  [SecurityCritical]
2344  internal extern bool IsUnloadingForcedFinalize();
2345 
2349  [MethodImpl(MethodImplOptions.InternalCall)]
2350  [SecuritySafeCritical]
2351  public extern bool IsFinalizingForUnload();
2352 
2353  [MethodImpl(MethodImplOptions.InternalCall)]
2354  [SecurityCritical]
2355  internal static extern void PublishAnonymouslyHostedDynamicMethodsAssembly(RuntimeAssembly assemblyHandle);
2356 
2360  [SecurityCritical]
2361  [Obsolete("AppDomain.AppendPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead. http://go.microsoft.com/fwlink/?linkid=14202")]
2362  public void AppendPrivatePath(string path)
2363  {
2364  if (path == null || path.Length == 0)
2365  {
2366  return;
2367  }
2368  string text = FusionStore.Value[5];
2369  StringBuilder stringBuilder = StringBuilderCache.Acquire();
2370  if (text != null && text.Length > 0)
2371  {
2372  stringBuilder.Append(text);
2373  if (text[text.Length - 1] != Path.PathSeparator && path[0] != Path.PathSeparator)
2374  {
2375  stringBuilder.Append(Path.PathSeparator);
2376  }
2377  }
2378  stringBuilder.Append(path);
2379  string stringAndRelease = StringBuilderCache.GetStringAndRelease(stringBuilder);
2380  InternalSetPrivateBinPath(stringAndRelease);
2381  }
2382 
2385  [SecurityCritical]
2386  [Obsolete("AppDomain.ClearPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead. http://go.microsoft.com/fwlink/?linkid=14202")]
2387  public void ClearPrivatePath()
2388  {
2389  InternalSetPrivateBinPath(string.Empty);
2390  }
2391 
2394  [SecurityCritical]
2395  [Obsolete("AppDomain.ClearShadowCopyPath has been deprecated. Please investigate the use of AppDomainSetup.ShadowCopyDirectories instead. http://go.microsoft.com/fwlink/?linkid=14202")]
2396  public void ClearShadowCopyPath()
2397  {
2398  InternalSetShadowCopyPath(string.Empty);
2399  }
2400 
2404  [SecurityCritical]
2405  [Obsolete("AppDomain.SetCachePath has been deprecated. Please investigate the use of AppDomainSetup.CachePath instead. http://go.microsoft.com/fwlink/?linkid=14202")]
2406  public void SetCachePath(string path)
2407  {
2408  InternalSetCachePath(path);
2409  }
2410 
2415  [SecurityCritical]
2416  public void SetData(string name, object data)
2417  {
2418  SetDataHelper(name, data, null);
2419  }
2420 
2429  [SecurityCritical]
2430  public void SetData(string name, object data, IPermission permission)
2431  {
2432  SetDataHelper(name, data, permission);
2433  }
2434 
2435  [SecurityCritical]
2436  private void SetDataHelper(string name, object data, IPermission permission)
2437  {
2438  if (name == null)
2439  {
2440  throw new ArgumentNullException("name");
2441  }
2442  if (name.Equals("TargetFrameworkName"))
2443  {
2444  _FusionStore.TargetFrameworkName = (string)data;
2445  return;
2446  }
2447  if (name.Equals("IgnoreSystemPolicy"))
2448  {
2449  lock (this)
2450  {
2451  if (!_HasSetPolicy)
2452  {
2453  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_SetData"));
2454  }
2455  }
2456  new PermissionSet(PermissionState.Unrestricted).Demand();
2457  }
2458  int num = AppDomainSetup.Locate(name);
2459  if (num == -1)
2460  {
2461  lock (((ICollection)LocalStore).SyncRoot)
2462  {
2463  LocalStore[name] = new object[2]
2464  {
2465  data,
2466  permission
2467  };
2468  }
2469  return;
2470  }
2471  if (permission != null)
2472  {
2473  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_SetData"));
2474  }
2475  switch (num)
2476  {
2477  case 2:
2478  FusionStore.DynamicBase = (string)data;
2479  break;
2480  case 3:
2481  FusionStore.DeveloperPath = (string)data;
2482  break;
2483  case 7:
2484  FusionStore.ShadowCopyDirectories = (string)data;
2485  break;
2486  case 11:
2487  if (data != null)
2488  {
2489  FusionStore.DisallowPublisherPolicy = true;
2490  }
2491  else
2492  {
2493  FusionStore.DisallowPublisherPolicy = false;
2494  }
2495  break;
2496  case 12:
2497  if (data != null)
2498  {
2499  FusionStore.DisallowCodeDownload = true;
2500  }
2501  else
2502  {
2503  FusionStore.DisallowCodeDownload = false;
2504  }
2505  break;
2506  case 13:
2507  if (data != null)
2508  {
2509  FusionStore.DisallowBindingRedirects = true;
2510  }
2511  else
2512  {
2513  FusionStore.DisallowBindingRedirects = false;
2514  }
2515  break;
2516  case 14:
2517  if (data != null)
2518  {
2519  FusionStore.DisallowApplicationBaseProbing = true;
2520  }
2521  else
2522  {
2523  FusionStore.DisallowApplicationBaseProbing = false;
2524  }
2525  break;
2526  case 15:
2527  FusionStore.SetConfigurationBytes((byte[])data);
2528  break;
2529  default:
2530  FusionStore.Value[num] = (string)data;
2531  break;
2532  }
2533  }
2534 
2541  [SecuritySafeCritical]
2542  public object GetData(string name)
2543  {
2544  if (name == null)
2545  {
2546  throw new ArgumentNullException("name");
2547  }
2548  switch (AppDomainSetup.Locate(name))
2549  {
2550  case -1:
2551  {
2552  if (name.Equals(AppDomainSetup.LoaderOptimizationKey))
2553  {
2554  return FusionStore.LoaderOptimization;
2555  }
2556  object[] value;
2557  lock (((ICollection)LocalStore).SyncRoot)
2558  {
2559  LocalStore.TryGetValue(name, out value);
2560  }
2561  if (value == null)
2562  {
2563  return null;
2564  }
2565  if (value[1] != null)
2566  {
2567  IPermission permission = (IPermission)value[1];
2568  permission.Demand();
2569  }
2570  return value[0];
2571  }
2572  case 0:
2573  return FusionStore.ApplicationBase;
2574  case 4:
2575  return FusionStore.ApplicationName;
2576  case 1:
2577  return FusionStore.ConfigurationFile;
2578  case 2:
2579  return FusionStore.DynamicBase;
2580  case 3:
2581  return FusionStore.DeveloperPath;
2582  case 5:
2583  return FusionStore.PrivateBinPath;
2584  case 6:
2585  return FusionStore.PrivateBinPathProbe;
2586  case 7:
2587  return FusionStore.ShadowCopyDirectories;
2588  case 8:
2589  return FusionStore.ShadowCopyFiles;
2590  case 9:
2591  return FusionStore.CachePath;
2592  case 10:
2593  return FusionStore.LicenseFile;
2594  case 11:
2595  return FusionStore.DisallowPublisherPolicy;
2596  case 12:
2597  return FusionStore.DisallowCodeDownload;
2598  case 13:
2599  return FusionStore.DisallowBindingRedirects;
2600  case 14:
2601  return FusionStore.DisallowApplicationBaseProbing;
2602  case 15:
2603  return FusionStore.GetConfigurationBytes();
2604  default:
2605  return null;
2606  }
2607  }
2608 
2612  public bool? IsCompatibilitySwitchSet(string value)
2613  {
2614  bool? result = (!_compatFlagsInitialized) ? null : new bool?(_compatFlags != null && _compatFlags.ContainsKey(value));
2615  return result;
2616  }
2617 
2620  [DllImport("kernel32.dll")]
2621  [Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. http://go.microsoft.com/fwlink/?linkid=14202", false)]
2622  public static extern int GetCurrentThreadId();
2623 
2631  [SecuritySafeCritical]
2632  [ReliabilityContract(Consistency.MayCorruptAppDomain, Cer.MayFail)]
2633  [SecurityPermission(SecurityAction.Demand, ControlAppDomain = true)]
2634  public static void Unload(AppDomain domain)
2635  {
2636  if (domain == null)
2637  {
2638  throw new ArgumentNullException("domain");
2639  }
2640  try
2641  {
2642  int idForUnload = GetIdForUnload(domain);
2643  if (idForUnload == 0)
2644  {
2645  throw new CannotUnloadAppDomainException();
2646  }
2647  nUnload(idForUnload);
2648  }
2649  catch (Exception ex)
2650  {
2651  throw ex;
2652  }
2653  }
2654 
2661  [SecurityCritical]
2662  [Obsolete("AppDomain policy levels are obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
2663  public void SetAppDomainPolicy(PolicyLevel domainPolicy)
2664  {
2665  if (domainPolicy == null)
2666  {
2667  throw new ArgumentNullException("domainPolicy");
2668  }
2669  if (!IsLegacyCasPolicyEnabled)
2670  {
2671  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyExplicit"));
2672  }
2673  lock (this)
2674  {
2675  if (_HasSetPolicy)
2676  {
2677  throw new PolicyException(Environment.GetResourceString("Policy_PolicyAlreadySet"));
2678  }
2679  _HasSetPolicy = true;
2680  nChangeSecurityPolicy();
2681  }
2682  SecurityManager.PolicyManager.AddLevel(domainPolicy);
2683  }
2684 
2691  [SecuritySafeCritical]
2692  [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlPrincipal)]
2693  public void SetThreadPrincipal(IPrincipal principal)
2694  {
2695  if (principal == null)
2696  {
2697  throw new ArgumentNullException("principal");
2698  }
2699  lock (this)
2700  {
2701  if (_DefaultPrincipal != null)
2702  {
2703  throw new PolicyException(Environment.GetResourceString("Policy_PrincipalTwice"));
2704  }
2705  _DefaultPrincipal = principal;
2706  }
2707  }
2708 
2712  [SecuritySafeCritical]
2713  [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlPrincipal)]
2715  {
2716  _PrincipalPolicy = policy;
2717  }
2718 
2722  [SecurityCritical]
2723  public override object InitializeLifetimeService()
2724  {
2725  return null;
2726  }
2727 
2732  public void DoCallBack(CrossAppDomainDelegate callBackDelegate)
2733  {
2734  if (callBackDelegate == null)
2735  {
2736  throw new ArgumentNullException("callBackDelegate");
2737  }
2738  callBackDelegate();
2739  }
2740 
2747  public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo)
2748  {
2749  return CreateDomain(friendlyName, securityInfo, null);
2750  }
2751 
2761  public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles)
2762  {
2763  AppDomainSetup appDomainSetup = new AppDomainSetup();
2764  appDomainSetup.ApplicationBase = appBasePath;
2765  appDomainSetup.PrivateBinPath = appRelativeSearchPath;
2766  if (shadowCopyFiles)
2767  {
2768  appDomainSetup.ShadowCopyFiles = "true";
2769  }
2770  return CreateDomain(friendlyName, securityInfo, appDomainSetup);
2771  }
2772 
2773  [MethodImpl(MethodImplOptions.InternalCall)]
2774  [SecurityCritical]
2775  private extern string GetDynamicDir();
2776 
2782  public static AppDomain CreateDomain(string friendlyName)
2783  {
2784  return CreateDomain(friendlyName, null, null);
2785  }
2786 
2787  [SecurityCritical]
2788  private static byte[] MarshalObject(object o)
2789  {
2790  CodeAccessPermission.Assert(allPossible: true);
2791  return Serialize(o);
2792  }
2793 
2794  [SecurityCritical]
2795  private static byte[] MarshalObjects(object o1, object o2, out byte[] blob2)
2796  {
2797  CodeAccessPermission.Assert(allPossible: true);
2798  byte[] result = Serialize(o1);
2799  blob2 = Serialize(o2);
2800  return result;
2801  }
2802 
2803  [SecurityCritical]
2804  private static object UnmarshalObject(byte[] blob)
2805  {
2806  CodeAccessPermission.Assert(allPossible: true);
2807  return Deserialize(blob);
2808  }
2809 
2810  [SecurityCritical]
2811  private static object UnmarshalObjects(byte[] blob1, byte[] blob2, out object o2)
2812  {
2813  CodeAccessPermission.Assert(allPossible: true);
2814  object result = Deserialize(blob1);
2815  o2 = Deserialize(blob2);
2816  return result;
2817  }
2818 
2819  [SecurityCritical]
2820  private static byte[] Serialize(object o)
2821  {
2822  if (o == null)
2823  {
2824  return null;
2825  }
2826  if (o is ISecurityEncodable)
2827  {
2828  SecurityElement securityElement = ((ISecurityEncodable)o).ToXml();
2829  MemoryStream memoryStream = new MemoryStream(4096);
2830  memoryStream.WriteByte(0);
2831  StreamWriter streamWriter = new StreamWriter(memoryStream, Encoding.UTF8);
2832  securityElement.ToWriter(streamWriter);
2833  streamWriter.Flush();
2834  return memoryStream.ToArray();
2835  }
2836  MemoryStream memoryStream2 = new MemoryStream();
2837  memoryStream2.WriteByte(1);
2838  CrossAppDomainSerializer.SerializeObject(o, memoryStream2);
2839  return memoryStream2.ToArray();
2840  }
2841 
2842  [SecurityCritical]
2843  private static object Deserialize(byte[] blob)
2844  {
2845  if (blob == null)
2846  {
2847  return null;
2848  }
2849  if (blob[0] == 0)
2850  {
2851  Parser parser = new Parser(blob, Tokenizer.ByteTokenEncoding.UTF8Tokens, 1);
2852  SecurityElement topElement = parser.GetTopElement();
2853  if (topElement.Tag.Equals("IPermission") || topElement.Tag.Equals("Permission"))
2854  {
2855  IPermission permission = XMLUtil.CreatePermission(topElement, PermissionState.None, ignoreTypeLoadFailures: false);
2856  if (permission == null)
2857  {
2858  return null;
2859  }
2860  permission.FromXml(topElement);
2861  return permission;
2862  }
2863  if (topElement.Tag.Equals("PermissionSet"))
2864  {
2865  PermissionSet permissionSet = new PermissionSet();
2866  permissionSet.FromXml(topElement, allowInternalOnly: false, ignoreTypeLoadFailures: false);
2867  return permissionSet;
2868  }
2869  if (topElement.Tag.Equals("PermissionToken"))
2870  {
2871  PermissionToken permissionToken = new PermissionToken();
2872  permissionToken.FromXml(topElement);
2873  return permissionToken;
2874  }
2875  return null;
2876  }
2877  object obj = null;
2878  using (MemoryStream stm = new MemoryStream(blob, 1, blob.Length - 1))
2879  {
2880  return CrossAppDomainSerializer.DeserializeObject(stm);
2881  }
2882  }
2883 
2884  [SecurityCritical]
2885  internal static void Pause()
2886  {
2887  AppDomainPauseManager.Instance.Pausing();
2888  AppDomainPauseManager.Instance.Paused();
2889  }
2890 
2891  [SecurityCritical]
2892  internal static void Resume()
2893  {
2894  if (AppDomainPauseManager.IsPaused)
2895  {
2896  AppDomainPauseManager.Instance.Resuming();
2897  AppDomainPauseManager.Instance.Resumed();
2898  }
2899  }
2900 
2901  private AppDomain()
2902  {
2903  throw new NotSupportedException(Environment.GetResourceString("NotSupported_Constructor"));
2904  }
2905 
2906  [MethodImpl(MethodImplOptions.InternalCall)]
2907  [SecuritySafeCritical]
2908  private extern int _nExecuteAssembly(RuntimeAssembly assembly, string[] args);
2909 
2910  internal int nExecuteAssembly(RuntimeAssembly assembly, string[] args)
2911  {
2912  return _nExecuteAssembly(assembly, args);
2913  }
2914 
2915  internal void CreateRemotingData()
2916  {
2917  lock (this)
2918  {
2919  if (_RemotingData == null)
2920  {
2921  _RemotingData = new DomainSpecificRemotingData();
2922  }
2923  }
2924  }
2925 
2926  [MethodImpl(MethodImplOptions.InternalCall)]
2927  [SecurityCritical]
2928  private extern string nGetFriendlyName();
2929 
2930  [MethodImpl(MethodImplOptions.InternalCall)]
2931  [SecurityCritical]
2932  private extern bool nIsDefaultAppDomainForEvidence();
2933 
2934  private void OnAssemblyLoadEvent(RuntimeAssembly LoadedAssembly)
2935  {
2936  AssemblyLoadEventHandler assemblyLoad = this.AssemblyLoad;
2937  if (assemblyLoad != null)
2938  {
2939  AssemblyLoadEventArgs args = new AssemblyLoadEventArgs(LoadedAssembly);
2940  assemblyLoad(this, args);
2941  }
2942  }
2943 
2944  [SecurityCritical]
2945  private RuntimeAssembly OnResourceResolveEvent(RuntimeAssembly assembly, string resourceName)
2946  {
2947  ResolveEventHandler resourceResolve = _ResourceResolve;
2948  if (resourceResolve == null)
2949  {
2950  return null;
2951  }
2952  Delegate[] invocationList = resourceResolve.GetInvocationList();
2953  int num = invocationList.Length;
2954  for (int i = 0; i < num; i++)
2955  {
2956  Assembly asm = ((ResolveEventHandler)invocationList[i])(this, new ResolveEventArgs(resourceName, assembly));
2957  RuntimeAssembly runtimeAssembly = GetRuntimeAssembly(asm);
2958  if (runtimeAssembly != null)
2959  {
2960  return runtimeAssembly;
2961  }
2962  }
2963  return null;
2964  }
2965 
2966  [SecurityCritical]
2967  private RuntimeAssembly OnTypeResolveEvent(RuntimeAssembly assembly, string typeName)
2968  {
2969  ResolveEventHandler typeResolve = _TypeResolve;
2970  if (typeResolve == null)
2971  {
2972  return null;
2973  }
2974  Delegate[] invocationList = typeResolve.GetInvocationList();
2975  int num = invocationList.Length;
2976  for (int i = 0; i < num; i++)
2977  {
2978  Assembly asm = ((ResolveEventHandler)invocationList[i])(this, new ResolveEventArgs(typeName, assembly));
2979  RuntimeAssembly runtimeAssembly = GetRuntimeAssembly(asm);
2980  if (runtimeAssembly != null)
2981  {
2982  return runtimeAssembly;
2983  }
2984  }
2985  return null;
2986  }
2987 
2988  [SecurityCritical]
2989  private RuntimeAssembly OnAssemblyResolveEvent(RuntimeAssembly assembly, string assemblyFullName)
2990  {
2991  ResolveEventHandler assemblyResolve = _AssemblyResolve;
2992  if (assemblyResolve == null)
2993  {
2994  return null;
2995  }
2996  Delegate[] invocationList = assemblyResolve.GetInvocationList();
2997  int num = invocationList.Length;
2998  for (int i = 0; i < num; i++)
2999  {
3000  Assembly asm = ((ResolveEventHandler)invocationList[i])(this, new ResolveEventArgs(assemblyFullName, assembly));
3001  RuntimeAssembly runtimeAssembly = GetRuntimeAssembly(asm);
3002  if (runtimeAssembly != null)
3003  {
3004  return runtimeAssembly;
3005  }
3006  }
3007  return null;
3008  }
3009 
3010  private RuntimeAssembly OnReflectionOnlyAssemblyResolveEvent(RuntimeAssembly assembly, string assemblyFullName)
3011  {
3012  ResolveEventHandler reflectionOnlyAssemblyResolve = this.ReflectionOnlyAssemblyResolve;
3013  if (reflectionOnlyAssemblyResolve != null)
3014  {
3015  Delegate[] invocationList = reflectionOnlyAssemblyResolve.GetInvocationList();
3016  int num = invocationList.Length;
3017  for (int i = 0; i < num; i++)
3018  {
3019  Assembly asm = ((ResolveEventHandler)invocationList[i])(this, new ResolveEventArgs(assemblyFullName, assembly));
3020  RuntimeAssembly runtimeAssembly = GetRuntimeAssembly(asm);
3021  if (runtimeAssembly != null)
3022  {
3023  return runtimeAssembly;
3024  }
3025  }
3026  }
3027  return null;
3028  }
3029 
3030  private RuntimeAssembly[] OnReflectionOnlyNamespaceResolveEvent(RuntimeAssembly assembly, string namespaceName)
3031  {
3032  return WindowsRuntimeMetadata.OnReflectionOnlyNamespaceResolveEvent(this, assembly, namespaceName);
3033  }
3034 
3035  private string[] OnDesignerNamespaceResolveEvent(string namespaceName)
3036  {
3037  return WindowsRuntimeMetadata.OnDesignerNamespaceResolveEvent(this, namespaceName);
3038  }
3039 
3040  internal static RuntimeAssembly GetRuntimeAssembly(Assembly asm)
3041  {
3042  if (asm == null)
3043  {
3044  return null;
3045  }
3046  RuntimeAssembly runtimeAssembly = asm as RuntimeAssembly;
3047  if (runtimeAssembly != null)
3048  {
3049  return runtimeAssembly;
3050  }
3051  AssemblyBuilder assemblyBuilder = asm as AssemblyBuilder;
3052  if (assemblyBuilder != null)
3053  {
3054  return assemblyBuilder.InternalAssembly;
3055  }
3056  return null;
3057  }
3058 
3059  private void TurnOnBindingRedirects()
3060  {
3061  _FusionStore.DisallowBindingRedirects = false;
3062  }
3063 
3064  [SecurityCritical]
3065  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
3066  internal static int GetIdForUnload(AppDomain domain)
3067  {
3069  {
3070  return RemotingServices.GetServerDomainIdForProxy(domain);
3071  }
3072  return domain.Id;
3073  }
3074 
3075  [MethodImpl(MethodImplOptions.InternalCall)]
3076  [SecurityCritical]
3077  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
3078  internal static extern bool IsDomainIdValid(int id);
3079 
3080  [MethodImpl(MethodImplOptions.InternalCall)]
3081  [SecurityCritical]
3082  internal static extern AppDomain GetDefaultDomain();
3083 
3084  internal IPrincipal GetThreadPrincipal()
3085  {
3086  IPrincipal principal = null;
3087  if (_DefaultPrincipal == null)
3088  {
3089  switch (_PrincipalPolicy)
3090  {
3091  case PrincipalPolicy.NoPrincipal:
3092  return null;
3093  case PrincipalPolicy.UnauthenticatedPrincipal:
3094  return new GenericPrincipal(new GenericIdentity("", ""), new string[1]
3095  {
3096  ""
3097  });
3098  case PrincipalPolicy.WindowsPrincipal:
3100  default:
3101  return null;
3102  }
3103  }
3104  return _DefaultPrincipal;
3105  }
3106 
3107  [SecurityCritical]
3108  internal void CreateDefaultContext()
3109  {
3110  lock (this)
3111  {
3112  if (_DefaultContext == null)
3113  {
3114  _DefaultContext = Context.CreateDefaultContext();
3115  }
3116  }
3117  }
3118 
3119  [SecurityCritical]
3120  internal Context GetDefaultContext()
3121  {
3122  if (_DefaultContext == null)
3123  {
3124  CreateDefaultContext();
3125  }
3126  return _DefaultContext;
3127  }
3128 
3129  [SecuritySafeCritical]
3130  internal static void CheckDomainCreationEvidence(AppDomainSetup creationDomainSetup, Evidence creationEvidence)
3131  {
3132  if (creationEvidence != null && !CurrentDomain.IsLegacyCasPolicyEnabled && (creationDomainSetup == null || creationDomainSetup.ApplicationTrust == null))
3133  {
3134  SecurityZone securityZone = CurrentDomain.EvidenceNoDemand.GetHostEvidence<Zone>()?.SecurityZone ?? SecurityZone.MyComputer;
3135  Zone hostEvidence = creationEvidence.GetHostEvidence<Zone>();
3136  if (hostEvidence != null && hostEvidence.SecurityZone != securityZone && hostEvidence.SecurityZone != 0)
3137  {
3138  throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
3139  }
3140  }
3141  }
3142 
3150  [SecuritySafeCritical]
3151  [SecurityPermission(SecurityAction.Demand, ControlAppDomain = true)]
3152  public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup info)
3153  {
3154  return InternalCreateDomain(friendlyName, securityInfo, info);
3155  }
3156 
3157  [SecurityCritical]
3158  internal static AppDomain InternalCreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup info)
3159  {
3160  if (friendlyName == null)
3161  {
3162  throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_String"));
3163  }
3164  CheckCreateDomainSupported();
3165  if (info == null)
3166  {
3167  info = new AppDomainSetup();
3168  }
3169  if (info.TargetFrameworkName == null)
3170  {
3171  info.TargetFrameworkName = CurrentDomain.GetTargetFrameworkName();
3172  }
3173  AppDomainManager domainManager = CurrentDomain.DomainManager;
3174  if (domainManager != null)
3175  {
3176  return domainManager.CreateDomain(friendlyName, securityInfo, info);
3177  }
3178  if (securityInfo != null)
3179  {
3180  new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
3181  CheckDomainCreationEvidence(info, securityInfo);
3182  }
3183  return nCreateDomain(friendlyName, info, securityInfo, (securityInfo == null) ? CurrentDomain.InternalEvidence : null, CurrentDomain.GetSecurityDescriptor());
3184  }
3185 
3197  public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup info, PermissionSet grantSet, params StrongName[] fullTrustAssemblies)
3198  {
3199  if (info == null)
3200  {
3201  throw new ArgumentNullException("info");
3202  }
3203  if (info.ApplicationBase == null)
3204  {
3205  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AppDomainSandboxAPINeedsExplicitAppBase"));
3206  }
3207  if (fullTrustAssemblies == null)
3208  {
3209  fullTrustAssemblies = new StrongName[0];
3210  }
3211  info.ApplicationTrust = new ApplicationTrust(grantSet, fullTrustAssemblies);
3212  return CreateDomain(friendlyName, securityInfo, info);
3213  }
3214 
3227  public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer adInit, string[] adInitArgs)
3228  {
3229  AppDomainSetup appDomainSetup = new AppDomainSetup();
3230  appDomainSetup.ApplicationBase = appBasePath;
3231  appDomainSetup.PrivateBinPath = appRelativeSearchPath;
3232  appDomainSetup.AppDomainInitializer = adInit;
3233  appDomainSetup.AppDomainInitializerArguments = adInitArgs;
3234  if (shadowCopyFiles)
3235  {
3236  appDomainSetup.ShadowCopyFiles = "true";
3237  }
3238  return CreateDomain(friendlyName, securityInfo, appDomainSetup);
3239  }
3240 
3241  [SecurityCritical]
3242  private void SetupFusionStore(AppDomainSetup info, AppDomainSetup oldInfo)
3243  {
3244  _FusionStore = info;
3245  if (oldInfo == null)
3246  {
3247  if (info.Value[0] == null || info.Value[1] == null)
3248  {
3249  AppDomain defaultDomain = GetDefaultDomain();
3250  if (this == defaultDomain)
3251  {
3252  info.SetupDefaults(RuntimeEnvironment.GetModuleFileName(), imageLocationAlreadyNormalized: true);
3253  }
3254  else
3255  {
3256  if (info.Value[1] == null)
3257  {
3258  info.ConfigurationFile = defaultDomain.FusionStore.Value[1];
3259  }
3260  if (info.Value[0] == null)
3261  {
3262  info.ApplicationBase = defaultDomain.FusionStore.Value[0];
3263  }
3264  if (info.Value[4] == null)
3265  {
3266  info.ApplicationName = defaultDomain.FusionStore.Value[4];
3267  }
3268  }
3269  }
3270  if (info.Value[5] == null)
3271  {
3272  info.PrivateBinPath = Environment.nativeGetEnvironmentVariable(AppDomainSetup.PrivateBinPathEnvironmentVariable);
3273  }
3274  if (info.DeveloperPath == null)
3275  {
3276  info.DeveloperPath = RuntimeEnvironment.GetDeveloperPath();
3277  }
3278  }
3279  IntPtr fusionContext = GetFusionContext();
3280  info.SetupFusionContext(fusionContext, oldInfo);
3281  if (info.LoaderOptimization != 0 || (oldInfo != null && info.LoaderOptimization != oldInfo.LoaderOptimization))
3282  {
3283  UpdateLoaderOptimization(info.LoaderOptimization);
3284  }
3285  }
3286 
3287  private static void RunInitializer(AppDomainSetup setup)
3288  {
3289  if (setup.AppDomainInitializer != null)
3290  {
3291  string[] args = null;
3292  if (setup.AppDomainInitializerArguments != null)
3293  {
3294  args = (string[])setup.AppDomainInitializerArguments.Clone();
3295  }
3296  setup.AppDomainInitializer(args);
3297  }
3298  }
3299 
3300  [SecurityCritical]
3301  private static object PrepareDataForSetup(string friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor, string sandboxName, string[] propertyNames, string[] propertyValues)
3302  {
3303  byte[] array = null;
3304  bool flag = false;
3305  EvidenceCollection evidenceCollection = null;
3306  if (providedSecurityInfo != null || creatorsSecurityInfo != null)
3307  {
3309  if (hostSecurityManager == null || !(hostSecurityManager.GetType() != typeof(HostSecurityManager)) || (hostSecurityManager.Flags & HostSecurityManagerOptions.HostAppDomainEvidence) != HostSecurityManagerOptions.HostAppDomainEvidence)
3310  {
3311  if (providedSecurityInfo != null && providedSecurityInfo.IsUnmodified && providedSecurityInfo.Target != null && providedSecurityInfo.Target is AppDomainEvidenceFactory)
3312  {
3313  providedSecurityInfo = null;
3314  flag = true;
3315  }
3316  if (creatorsSecurityInfo != null && creatorsSecurityInfo.IsUnmodified && creatorsSecurityInfo.Target != null && creatorsSecurityInfo.Target is AppDomainEvidenceFactory)
3317  {
3318  creatorsSecurityInfo = null;
3319  flag = true;
3320  }
3321  }
3322  }
3323  if (providedSecurityInfo != null || creatorsSecurityInfo != null)
3324  {
3325  evidenceCollection = new EvidenceCollection();
3326  evidenceCollection.ProvidedSecurityInfo = providedSecurityInfo;
3327  evidenceCollection.CreatorsSecurityInfo = creatorsSecurityInfo;
3328  }
3329  if (evidenceCollection != null)
3330  {
3331  array = CrossAppDomainSerializer.SerializeObject(evidenceCollection).GetBuffer();
3332  }
3333  AppDomainInitializerInfo appDomainInitializerInfo = null;
3334  if (setup != null && setup.AppDomainInitializer != null)
3335  {
3336  appDomainInitializerInfo = new AppDomainInitializerInfo(setup.AppDomainInitializer);
3337  }
3338  AppDomainSetup appDomainSetup = new AppDomainSetup(setup, copyDomainBoundData: false);
3339  return new object[9]
3340  {
3341  friendlyName,
3342  appDomainSetup,
3343  parentSecurityDescriptor,
3344  flag,
3345  array,
3346  appDomainInitializerInfo,
3347  sandboxName,
3348  propertyNames,
3349  propertyValues
3350  };
3351  }
3352 
3353  [MethodImpl(MethodImplOptions.NoInlining)]
3354  [SecurityCritical]
3355  private static object Setup(object arg)
3356  {
3357  object[] array = (object[])arg;
3358  string friendlyName = (string)array[0];
3359  AppDomainSetup appDomainSetup = (AppDomainSetup)array[1];
3360  IntPtr parentSecurityDescriptor = (IntPtr)array[2];
3361  bool generateDefaultEvidence = (bool)array[3];
3362  byte[] array2 = (byte[])array[4];
3363  AppDomainInitializerInfo appDomainInitializerInfo = (AppDomainInitializerInfo)array[5];
3364  string text = (string)array[6];
3365  string[] array3 = (string[])array[7];
3366  string[] array4 = (string[])array[8];
3367  Evidence evidence = null;
3368  Evidence creatorsSecurityInfo = null;
3369  AppDomain currentDomain = CurrentDomain;
3370  AppDomainSetup appDomainSetup2 = new AppDomainSetup(appDomainSetup, copyDomainBoundData: false);
3371  if (array3 != null && array4 != null)
3372  {
3373  for (int i = 0; i < array3.Length; i++)
3374  {
3375  if (array3[i] == "APPBASE")
3376  {
3377  if (array4[i] == null)
3378  {
3379  throw new ArgumentNullException("APPBASE");
3380  }
3381  if (Path.IsRelative(array4[i]))
3382  {
3383  throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"));
3384  }
3385  appDomainSetup2.ApplicationBase = NormalizePath(array4[i], fullCheck: true);
3386  }
3387  else if (array3[i] == "LOCATION_URI" && evidence == null)
3388  {
3389  evidence = new Evidence();
3390  evidence.AddHostEvidence(new Url(array4[i]));
3391  currentDomain.SetDataHelper(array3[i], array4[i], null);
3392  }
3393  else if (array3[i] == "LOADER_OPTIMIZATION")
3394  {
3395  if (array4[i] == null)
3396  {
3397  throw new ArgumentNullException("LOADER_OPTIMIZATION");
3398  }
3399  switch (array4[i])
3400  {
3401  case "SingleDomain":
3402  appDomainSetup2.LoaderOptimization = LoaderOptimization.SingleDomain;
3403  break;
3404  case "MultiDomain":
3405  appDomainSetup2.LoaderOptimization = LoaderOptimization.MultiDomain;
3406  break;
3407  case "MultiDomainHost":
3408  appDomainSetup2.LoaderOptimization = LoaderOptimization.MultiDomainHost;
3409  break;
3410  case "NotSpecified":
3411  appDomainSetup2.LoaderOptimization = LoaderOptimization.NotSpecified;
3412  break;
3413  default:
3414  throw new ArgumentException(Environment.GetResourceString("Argument_UnrecognizedLoaderOptimization"), "LOADER_OPTIMIZATION");
3415  }
3416  }
3417  }
3418  }
3419  AppDomainSortingSetupInfo appDomainSortingSetupInfo = appDomainSetup2._AppDomainSortingSetupInfo;
3420  if (appDomainSortingSetupInfo != null && (appDomainSortingSetupInfo._pfnIsNLSDefinedString == IntPtr.Zero || appDomainSortingSetupInfo._pfnCompareStringEx == IntPtr.Zero || appDomainSortingSetupInfo._pfnLCMapStringEx == IntPtr.Zero || appDomainSortingSetupInfo._pfnFindNLSStringEx == IntPtr.Zero || appDomainSortingSetupInfo._pfnCompareStringOrdinal == IntPtr.Zero || appDomainSortingSetupInfo._pfnGetNLSVersionEx == IntPtr.Zero) && (!(appDomainSortingSetupInfo._pfnIsNLSDefinedString == IntPtr.Zero) || !(appDomainSortingSetupInfo._pfnCompareStringEx == IntPtr.Zero) || !(appDomainSortingSetupInfo._pfnLCMapStringEx == IntPtr.Zero) || !(appDomainSortingSetupInfo._pfnFindNLSStringEx == IntPtr.Zero) || !(appDomainSortingSetupInfo._pfnCompareStringOrdinal == IntPtr.Zero) || !(appDomainSortingSetupInfo._pfnGetNLSVersionEx == IntPtr.Zero)))
3421  {
3422  throw new ArgumentException(Environment.GetResourceString("ArgumentException_NotAllCustomSortingFuncsDefined"));
3423  }
3424  currentDomain.SetupFusionStore(appDomainSetup2, null);
3425  AppDomainSetup fusionStore = currentDomain.FusionStore;
3426  if (array2 != null)
3427  {
3428  EvidenceCollection evidenceCollection = (EvidenceCollection)CrossAppDomainSerializer.DeserializeObject(new MemoryStream(array2));
3429  evidence = evidenceCollection.ProvidedSecurityInfo;
3430  creatorsSecurityInfo = evidenceCollection.CreatorsSecurityInfo;
3431  }
3432  currentDomain.nSetupFriendlyName(friendlyName);
3433  if (appDomainSetup != null && appDomainSetup.SandboxInterop)
3434  {
3435  currentDomain.nSetDisableInterfaceCache();
3436  }
3437  if (fusionStore.AppDomainManagerAssembly != null && fusionStore.AppDomainManagerType != null)
3438  {
3439  currentDomain.SetAppDomainManagerType(fusionStore.AppDomainManagerAssembly, fusionStore.AppDomainManagerType);
3440  }
3441  currentDomain.PartialTrustVisibleAssemblies = fusionStore.PartialTrustVisibleAssemblies;
3442  currentDomain.CreateAppDomainManager();
3443  currentDomain.InitializeDomainSecurity(evidence, creatorsSecurityInfo, generateDefaultEvidence, parentSecurityDescriptor, publishAppDomain: true);
3444  if (appDomainInitializerInfo != null)
3445  {
3446  fusionStore.AppDomainInitializer = appDomainInitializerInfo.Unwrap();
3447  }
3448  RunInitializer(fusionStore);
3449  ObjectHandle obj = null;
3450  if (fusionStore.ActivationArguments != null && fusionStore.ActivationArguments.ActivateInstance)
3451  {
3452  obj = Activator.CreateInstance(currentDomain.ActivationContext);
3453  }
3454  return RemotingServices.MarshalInternal(obj, null, null);
3455  }
3456 
3457  [SecuritySafeCritical]
3458  internal static string NormalizePath(string path, bool fullCheck)
3459  {
3460  return Path.LegacyNormalizePath(path, fullCheck, 260, expandShortPaths: true);
3461  }
3462 
3463  [SecuritySafeCritical]
3464  [PermissionSet(SecurityAction.Assert, Unrestricted = true)]
3465  private bool IsAssemblyOnAptcaVisibleList(RuntimeAssembly assembly)
3466  {
3467  if (_aptcaVisibleAssemblies == null)
3468  {
3469  return false;
3470  }
3471  AssemblyName name = assembly.GetName();
3472  string nameWithPublicKey = name.GetNameWithPublicKey();
3473  nameWithPublicKey = nameWithPublicKey.ToUpperInvariant();
3474  int num = Array.BinarySearch(_aptcaVisibleAssemblies, nameWithPublicKey, StringComparer.OrdinalIgnoreCase);
3475  return num >= 0;
3476  }
3477 
3478  [SecurityCritical]
3479  private unsafe bool IsAssemblyOnAptcaVisibleListRaw(char* namePtr, int nameLen, byte* keyTokenPtr, int keyTokenLen)
3480  {
3481  if (_aptcaVisibleAssemblies == null)
3482  {
3483  return false;
3484  }
3485  string name = new string(namePtr, 0, nameLen);
3486  byte[] array = new byte[keyTokenLen];
3487  for (int i = 0; i < array.Length; i++)
3488  {
3489  array[i] = keyTokenPtr[i];
3490  }
3491  AssemblyName assemblyName = new AssemblyName();
3492  assemblyName.Name = name;
3493  assemblyName.SetPublicKeyToken(array);
3494  try
3495  {
3496  int num = Array.BinarySearch(_aptcaVisibleAssemblies, assemblyName, new CAPTCASearcher());
3497  return num >= 0;
3498  }
3499  catch (InvalidOperationException)
3500  {
3501  return false;
3502  }
3503  }
3504 
3505  [SecurityCritical]
3506  private void SetupDomain(bool allowRedirects, string path, string configFile, string[] propertyNames, string[] propertyValues)
3507  {
3508  lock (this)
3509  {
3510  if (_FusionStore == null)
3511  {
3512  AppDomainSetup appDomainSetup = new AppDomainSetup();
3513  appDomainSetup.SetupDefaults(RuntimeEnvironment.GetModuleFileName(), imageLocationAlreadyNormalized: true);
3514  if (path != null)
3515  {
3516  appDomainSetup.Value[0] = path;
3517  }
3518  if (configFile != null)
3519  {
3520  appDomainSetup.Value[1] = configFile;
3521  }
3522  if (!allowRedirects)
3523  {
3524  appDomainSetup.DisallowBindingRedirects = true;
3525  }
3526  if (propertyNames != null)
3527  {
3528  for (int i = 0; i < propertyNames.Length; i++)
3529  {
3530  if (string.Equals(propertyNames[i], "PARTIAL_TRUST_VISIBLE_ASSEMBLIES", StringComparison.Ordinal) && propertyValues[i] != null)
3531  {
3532  if (propertyValues[i].Length > 0)
3533  {
3534  appDomainSetup.PartialTrustVisibleAssemblies = propertyValues[i].Split(';');
3535  }
3536  else
3537  {
3538  appDomainSetup.PartialTrustVisibleAssemblies = new string[0];
3539  }
3540  }
3541  }
3542  }
3543  PartialTrustVisibleAssemblies = appDomainSetup.PartialTrustVisibleAssemblies;
3544  SetupFusionStore(appDomainSetup, null);
3545  }
3546  }
3547  }
3548 
3549  [SecurityCritical]
3550  private void SetupLoaderOptimization(LoaderOptimization policy)
3551  {
3552  if (policy != 0)
3553  {
3554  FusionStore.LoaderOptimization = policy;
3555  UpdateLoaderOptimization(FusionStore.LoaderOptimization);
3556  }
3557  }
3558 
3559  [MethodImpl(MethodImplOptions.InternalCall)]
3560  [SecurityCritical]
3561  internal extern IntPtr GetFusionContext();
3562 
3563  [MethodImpl(MethodImplOptions.InternalCall)]
3564  [SecurityCritical]
3565  internal extern IntPtr GetSecurityDescriptor();
3566 
3567  [MethodImpl(MethodImplOptions.InternalCall)]
3568  [SecurityCritical]
3569  internal static extern AppDomain nCreateDomain(string friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor);
3570 
3571  [MethodImpl(MethodImplOptions.InternalCall)]
3572  [SecurityCritical]
3573  internal static extern ObjRef nCreateInstance(string friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor);
3574 
3575  [SecurityCritical]
3576  private void SetupDomainSecurity(Evidence appDomainEvidence, IntPtr creatorsSecurityDescriptor, bool publishAppDomain)
3577  {
3578  Evidence o = appDomainEvidence;
3579  SetupDomainSecurity(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref o), creatorsSecurityDescriptor, publishAppDomain);
3580  }
3581 
3582  [DllImport("QCall", CharSet = CharSet.Unicode)]
3583  [SecurityCritical]
3584  [SuppressUnmanagedCodeSecurity]
3585  private static extern void SetupDomainSecurity(AppDomainHandle appDomain, ObjectHandleOnStack appDomainEvidence, IntPtr creatorsSecurityDescriptor, [MarshalAs(UnmanagedType.Bool)] bool publishAppDomain);
3586 
3587  [MethodImpl(MethodImplOptions.InternalCall)]
3588  [SecurityCritical]
3589  private extern void nSetupFriendlyName(string friendlyName);
3590 
3591  [MethodImpl(MethodImplOptions.InternalCall)]
3592  private extern void nSetDisableInterfaceCache();
3593 
3594  [MethodImpl(MethodImplOptions.InternalCall)]
3595  [SecurityCritical]
3596  internal extern void UpdateLoaderOptimization(LoaderOptimization optimization);
3597 
3601  [SecurityCritical]
3602  [Obsolete("AppDomain.SetShadowCopyPath has been deprecated. Please investigate the use of AppDomainSetup.ShadowCopyDirectories instead. http://go.microsoft.com/fwlink/?linkid=14202")]
3603  public void SetShadowCopyPath(string path)
3604  {
3605  InternalSetShadowCopyPath(path);
3606  }
3607 
3610  [SecurityCritical]
3611  [Obsolete("AppDomain.SetShadowCopyFiles has been deprecated. Please investigate the use of AppDomainSetup.ShadowCopyFiles instead. http://go.microsoft.com/fwlink/?linkid=14202")]
3612  public void SetShadowCopyFiles()
3613  {
3614  InternalSetShadowCopyFiles();
3615  }
3616 
3620  [SecurityCritical]
3621  [Obsolete("AppDomain.SetDynamicBase has been deprecated. Please investigate the use of AppDomainSetup.DynamicBase instead. http://go.microsoft.com/fwlink/?linkid=14202")]
3622  public void SetDynamicBase(string path)
3623  {
3624  InternalSetDynamicBase(path);
3625  }
3626 
3627  [SecurityCritical]
3628  internal void InternalSetShadowCopyPath(string path)
3629  {
3630  if (path != null)
3631  {
3632  IntPtr fusionContext = GetFusionContext();
3633  AppDomainSetup.UpdateContextProperty(fusionContext, AppDomainSetup.ShadowCopyDirectoriesKey, path);
3634  }
3635  FusionStore.ShadowCopyDirectories = path;
3636  }
3637 
3638  [SecurityCritical]
3639  internal void InternalSetShadowCopyFiles()
3640  {
3641  IntPtr fusionContext = GetFusionContext();
3642  AppDomainSetup.UpdateContextProperty(fusionContext, AppDomainSetup.ShadowCopyFilesKey, "true");
3643  FusionStore.ShadowCopyFiles = "true";
3644  }
3645 
3646  [SecurityCritical]
3647  internal void InternalSetCachePath(string path)
3648  {
3649  FusionStore.CachePath = path;
3650  if (FusionStore.Value[9] != null)
3651  {
3652  IntPtr fusionContext = GetFusionContext();
3653  AppDomainSetup.UpdateContextProperty(fusionContext, AppDomainSetup.CachePathKey, FusionStore.Value[9]);
3654  }
3655  }
3656 
3657  [SecurityCritical]
3658  internal void InternalSetPrivateBinPath(string path)
3659  {
3660  IntPtr fusionContext = GetFusionContext();
3661  AppDomainSetup.UpdateContextProperty(fusionContext, AppDomainSetup.PrivateBinPathKey, path);
3662  FusionStore.PrivateBinPath = path;
3663  }
3664 
3665  [SecurityCritical]
3666  internal void InternalSetDynamicBase(string path)
3667  {
3668  FusionStore.DynamicBase = path;
3669  if (FusionStore.Value[2] != null)
3670  {
3671  IntPtr fusionContext = GetFusionContext();
3672  AppDomainSetup.UpdateContextProperty(fusionContext, AppDomainSetup.DynamicBaseKey, FusionStore.Value[2]);
3673  }
3674  }
3675 
3676  [MethodImpl(MethodImplOptions.InternalCall)]
3677  [SecurityCritical]
3678  internal extern string IsStringInterned(string str);
3679 
3680  [MethodImpl(MethodImplOptions.InternalCall)]
3681  [SecurityCritical]
3682  internal extern string GetOrInternString(string str);
3683 
3684  [DllImport("QCall", CharSet = CharSet.Unicode)]
3685  [SecurityCritical]
3686  [SuppressUnmanagedCodeSecurity]
3687  private static extern void GetGrantSet(AppDomainHandle domain, ObjectHandleOnStack retGrantSet);
3688 
3689  [DllImport("QCall", CharSet = CharSet.Unicode)]
3690  [SecurityCritical]
3691  [SuppressUnmanagedCodeSecurity]
3692  [return: MarshalAs(UnmanagedType.Bool)]
3693  private static extern bool GetIsLegacyCasPolicyEnabled(AppDomainHandle domain);
3694 
3695  [SecuritySafeCritical]
3696  internal PermissionSet GetHomogenousGrantSet(Evidence evidence)
3697  {
3698  if (_IsFastFullTrustDomain)
3699  {
3700  return new PermissionSet(PermissionState.Unrestricted);
3701  }
3702  if (evidence.GetDelayEvaluatedHostEvidence<StrongName>() != null)
3703  {
3704  foreach (StrongName fullTrustAssembly in ApplicationTrust.FullTrustAssemblies)
3705  {
3706  StrongNameMembershipCondition strongNameMembershipCondition = new StrongNameMembershipCondition(fullTrustAssembly.PublicKey, fullTrustAssembly.Name, fullTrustAssembly.Version);
3707  object usedEvidence = null;
3708  if (((IReportMatchMembershipCondition)strongNameMembershipCondition).Check(evidence, out usedEvidence))
3709  {
3710  IDelayEvaluatedEvidence delayEvaluatedEvidence = usedEvidence as IDelayEvaluatedEvidence;
3711  if (usedEvidence != null)
3712  {
3713  delayEvaluatedEvidence.MarkUsed();
3714  }
3715  return new PermissionSet(PermissionState.Unrestricted);
3716  }
3717  }
3718  }
3720  }
3721 
3722  [MethodImpl(MethodImplOptions.InternalCall)]
3723  [SecurityCritical]
3724  private extern void nChangeSecurityPolicy();
3725 
3726  [MethodImpl(MethodImplOptions.InternalCall)]
3727  [SecurityCritical]
3728  [ReliabilityContract(Consistency.MayCorruptAppDomain, Cer.MayFail)]
3729  internal static extern void nUnload(int domainInternal);
3730 
3747  public object CreateInstanceAndUnwrap(string assemblyName, string typeName)
3748  {
3749  return CreateInstance(assemblyName, typeName)?.Unwrap();
3750  }
3751 
3770  public object CreateInstanceAndUnwrap(string assemblyName, string typeName, object[] activationAttributes)
3771  {
3772  return CreateInstance(assemblyName, typeName, activationAttributes)?.Unwrap();
3773  }
3774 
3799  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceAndUnwrap which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
3800  public object CreateInstanceAndUnwrap(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
3801  {
3802  return CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes)?.Unwrap();
3803  }
3804 
3829  public object CreateInstanceAndUnwrap(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
3830  {
3831  return CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes)?.Unwrap();
3832  }
3833 
3851  public object CreateInstanceFromAndUnwrap(string assemblyName, string typeName)
3852  {
3853  return CreateInstanceFrom(assemblyName, typeName)?.Unwrap();
3854  }
3855 
3875  public object CreateInstanceFromAndUnwrap(string assemblyName, string typeName, object[] activationAttributes)
3876  {
3877  return CreateInstanceFrom(assemblyName, typeName, activationAttributes)?.Unwrap();
3878  }
3879 
3905  [Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFromAndUnwrap which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
3906  public object CreateInstanceFromAndUnwrap(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
3907  {
3908  return CreateInstanceFrom(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes)?.Unwrap();
3909  }
3910 
3936  public object CreateInstanceFromAndUnwrap(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
3937  {
3938  return CreateInstanceFrom(assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes)?.Unwrap();
3939  }
3940 
3941  [MethodImpl(MethodImplOptions.InternalCall)]
3942  [SecuritySafeCritical]
3943  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
3944  internal extern int GetId();
3945 
3949  public bool IsDefaultAppDomain()
3950  {
3951  if (GetId() == 1)
3952  {
3953  return true;
3954  }
3955  return false;
3956  }
3957 
3958  private static AppDomainSetup InternalCreateDomainSetup(string imageLocation)
3959  {
3960  int num = imageLocation.LastIndexOf('\\');
3961  AppDomainSetup appDomainSetup = new AppDomainSetup();
3962  appDomainSetup.ApplicationBase = imageLocation.Substring(0, num + 1);
3963  StringBuilder stringBuilder = new StringBuilder(imageLocation.Substring(num + 1));
3964  stringBuilder.Append(AppDomainSetup.ConfigurationExtension);
3965  appDomainSetup.ConfigurationFile = stringBuilder.ToString();
3966  return appDomainSetup;
3967  }
3968 
3969  private static AppDomain InternalCreateDomain(string imageLocation)
3970  {
3971  AppDomainSetup info = InternalCreateDomainSetup(imageLocation);
3972  return CreateDomain("Validator", null, info);
3973  }
3974 
3975  [MethodImpl(MethodImplOptions.InternalCall)]
3976  [SecurityCritical]
3977  private static extern void nEnableMonitoring();
3978 
3979  [MethodImpl(MethodImplOptions.InternalCall)]
3980  [SecurityCritical]
3981  private static extern bool nMonitoringIsEnabled();
3982 
3983  [MethodImpl(MethodImplOptions.InternalCall)]
3984  [SecurityCritical]
3985  private extern long nGetTotalProcessorTime();
3986 
3987  [MethodImpl(MethodImplOptions.InternalCall)]
3988  [SecurityCritical]
3989  private extern long nGetTotalAllocatedMemorySize();
3990 
3991  [MethodImpl(MethodImplOptions.InternalCall)]
3992  [SecurityCritical]
3993  private extern long nGetLastSurvivedMemorySize();
3994 
3995  [MethodImpl(MethodImplOptions.InternalCall)]
3996  [SecurityCritical]
3997  private static extern long nGetLastSurvivedProcessMemorySize();
3998 
3999  [SecurityCritical]
4000  private void InternalSetDomainContext(string imageLocation)
4001  {
4002  SetupFusionStore(InternalCreateDomainSetup(imageLocation), null);
4003  }
4004 
4007  [__DynamicallyInvokable]
4008  public new Type GetType()
4009  {
4010  return base.GetType();
4011  }
4012 
4016  void _AppDomain.GetTypeInfoCount(out uint pcTInfo)
4017  {
4018  throw new NotImplementedException();
4019  }
4020 
4026  void _AppDomain.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
4027  {
4028  throw new NotImplementedException();
4029  }
4030 
4038  void _AppDomain.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
4039  {
4040  throw new NotImplementedException();
4041  }
4042 
4053  void _AppDomain.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
4054  {
4055  throw new NotImplementedException();
4056  }
4057  }
4058 }
bool IsFinalizingForUnload()
Indicates whether this application domain is unloading, and the objects it contains are being finaliz...
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
void ClearPrivatePath()
Resets the path that specifies the location of private assemblies to the empty string ("").
Definition: AppDomain.cs:2387
AppDomainManagerInitializationOptions
Specifies the action that a custom application domain manager takes when initializing a new domain.
override string ToString()
Obtains a string representation that includes the friendly name of the application domain and any con...
Definition: AppDomain.cs:2297
EventHandler< FirstChanceExceptionEventArgs > FirstChanceException
Occurs when an exception is thrown in managed code, before the runtime searches the call stack for an...
Definition: AppDomain.cs:736
ObjectHandle CreateInstance(string assemblyName, string typeName)
Creates a new instance of the specified type defined in the specified assembly.
Definition: AppDomain.cs:1504
ResolveEventHandler ResourceResolve
Occurs when the resolution of a resource fails because the resource is not a valid linked or embedded...
Definition: AppDomain.cs:617
Enables code to check the Windows group membership of a Windows user.
static string NewLine
Gets the newline string defined for this environment.
Definition: Environment.cs:449
static Assembly ReflectionOnlyLoad(string assemblyString)
Loads an assembly into the reflection-only context, given its display name.
Definition: Assembly.cs:546
override void WriteByte(byte value)
Writes a byte to the current stream at the current position.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Encapsulates security decisions about an application. This class cannot be inherited.
The exception that is thrown when there is an attempt to dereference a null object reference.
Describes a set of security permissions applied to code. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
Contains static methods for retrieving custom attributes.
IList< StrongName > FullTrustAssemblies
Gets the list of full-trust assemblies for this application trust.
Gets an object's T:System.Security.Policy.Evidence.
static Assembly ReflectionOnlyLoadFrom(string assemblyFile)
Loads an assembly into the reflection-only context, given its path.
Definition: Assembly.cs:392
long MonitoringTotalAllocatedMemorySize
Gets the total size, in bytes, of all memory allocations that have been made by the application domai...
Definition: AppDomain.cs:542
virtual ApplicationTrust DetermineApplicationTrust(Evidence applicationEvidence, Evidence activatorEvidence, TrustManagerContext context)
Determines whether an application should be executed.
static void PrepareContractedDelegate(Delegate d)
Provides a way for applications to dynamically prepare T:System.AppDomain event delegates.
static ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName)
Creates an instance of the COM object whose name is specified, using the named assembly file and the ...
Definition: Activator.cs:832
int ExecuteAssemblyByName(string assemblyName, Evidence assemblySecurity)
Executes an assembly given its display name, using the specified evidence.
Definition: AppDomain.cs:2177
string TargetFrameworkName
Gets or sets a string that specifies the target version and profile of the .NET Framework for the app...
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
static ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName)
Creates an instance of the type whose name is specified, using the named assembly file and default co...
Definition: Activator.cs:339
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
static Assembly Load(string assemblyString)
Loads an assembly given the long form of its name.
Definition: Assembly.cs:507
Provides the strong name of a code assembly as evidence for policy evaluation. This class cannot be i...
Definition: StrongName.cs:12
Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
Loads the T:System.Reflection.Assembly with a common object file format (COFF) based image containing...
Definition: AppDomain.cs:1940
LoaderOptimization
An enumeration used with the T:System.LoaderOptimizationAttribute class to specify loader optimizatio...
SecurityZone
Defines the integer values corresponding to security zones used by security policy.
Definition: SecurityZone.cs:8
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable< CustomAttributeBuilder > assemblyAttributes, SecurityContextSource securityContextSource)
Defines a dynamic assembly with the specified name, access mode, and custom attributes,...
Definition: AppDomain.cs:1244
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
int ExecuteAssembly(string assemblyFile)
Executes the assembly contained in the specified file.
Definition: AppDomain.cs:2005
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, bool isSynchronized, IEnumerable< CustomAttributeBuilder > assemblyAttributes)
Defines a dynamic assembly using the specified name, access mode, storage directory,...
Definition: AppDomain.cs:1451
string BaseDirectory
Gets the base directory that the assembly resolver uses to probe for assemblies.
Definition: AppDomain.cs:323
int ExecuteAssemblyByName(string assemblyName, params string[] args)
Executes the assembly given its display name, using the specified arguments.
Definition: AppDomain.cs:2225
object CreateInstanceAndUnwrap(string assemblyName, string typeName, object[] activationAttributes)
Creates a new instance of the specified type. Parameters specify the assembly where the type is defin...
Definition: AppDomain.cs:3770
Assembly Load(AssemblyName assemblyRef)
Loads an T:System.Reflection.Assembly given its T:System.Reflection.AssemblyName.
Definition: AppDomain.cs:1863
Provides the security zone of a code assembly as evidence for policy evaluation. This class cannot be...
Definition: Zone.cs:10
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup info, PermissionSet grantSet, params StrongName[] fullTrustAssemblies)
Creates a new application domain using the specified name, evidence, application domain setup informa...
Definition: AppDomain.cs:3197
override object InitializeLifetimeService()
Gives the T:System.AppDomain an infinite lifetime by preventing a lease from being created.
Definition: AppDomain.cs:2723
Defines the basic functionality of a principal object.
Definition: IPrincipal.cs:8
PermissionSet PermissionSet
Gets or sets the T:System.Security.PermissionSet of the policy statement.
string ShadowCopyFiles
Gets or sets a string that indicates whether shadow copying is turned on or off.
void SetThreadPrincipal(IPrincipal principal)
Sets the default principal object to be attached to threads if they attempt to bind to a principal wh...
Definition: AppDomain.cs:2693
Identifies the activation context for the current application. This class cannot be inherited.
Represents the security policy levels for the common language runtime. This class cannot be inherited...
Definition: PolicyLevel.cs:15
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, Evidence evidence)
Defines a dynamic assembly using the specified name, access mode, and evidence.
Definition: AppDomain.cs:1279
Provides the functionality that allows a common language runtime host to participate in the flow,...
static long MonitoringSurvivedProcessMemorySize
Gets the total bytes that survived from the last collection for all application domains in the proces...
Definition: AppDomain.cs:577
ObjectHandle CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
Creates a new instance of the specified type defined in the specified assembly. Parameters specify a ...
Definition: AppDomain.cs:1705
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
Definition: BindingFlags.cs:10
Definition: __Canon.cs:3
void SetDynamicBase(string path)
Establishes the specified directory path as the base directory for subdirectories where dynamically g...
Definition: AppDomain.cs:3622
virtual void InitializeNewDomain(AppDomainSetup appDomainInfo)
Initializes the new application domain.
HostSecurityManagerOptions
Specifies the security policy components to be used by the host security manager.
static WindowsIdentity GetCurrent()
Returns a T:System.Security.Principal.WindowsIdentity object that represents the current Windows user...
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir)
Defines a dynamic assembly using the specified name, access mode, and storage directory.
Definition: AppDomain.cs:1261
string FriendlyName
Gets the friendly name of this application domain.
Definition: AppDomain.cs:312
void AppendPrivatePath(string path)
Appends the specified directory name to the private path list.
Definition: AppDomain.cs:2362
ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, object[] activationAttributes)
Creates a new instance of the specified type defined in the specified assembly file.
Definition: AppDomain.cs:1669
LoaderOptimization LoaderOptimization
Specifies the optimization policy used to load an executable.
StrongNamePublicKeyBlob PublicKey
Gets the T:System.Security.Permissions.StrongNamePublicKeyBlob of the current T:System....
Definition: StrongName.cs:28
Stores all relevant information required to generate a proxy in order to communicate with a remote ob...
Definition: ObjRef.cs:19
int Id
Gets an integer that uniquely identifies the application domain within the process.
Definition: AppDomain.cs:491
string RelativeSearchPath
Gets the path under the base directory where the assembly resolver should probe for private assemblie...
Definition: AppDomain.cs:328
Version Version
Gets the T:System.Version of the current T:System.Security.Policy.StrongName.
Definition: StrongName.cs:36
static void Unload(AppDomain domain)
Unloads the specified application domain.
Definition: AppDomain.cs:2634
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
Defines a dynamic assembly using the specified name, access mode, storage directory,...
Definition: AppDomain.cs:1339
ActivationContext ActivationContext
Gets the activation context for the current application domain.
Definition: AppDomain.cs:350
int ExecuteAssemblyByName(string assemblyName, Evidence assemblySecurity, params string[] args)
Executes the assembly given its display name, using the specified evidence and arguments.
Definition: AppDomain.cs:2198
ApplicationIdentity ApplicationIdentity
Gets the identity of the application in the application domain.
Definition: AppDomain.cs:361
SecurityContextSource
Identifies the source for the security context.
void Demand()
Throws a T:System.Security.SecurityException at run time if the security requirement is not met.
Evidence Evidence
Gets the T:System.Security.Policy.Evidence associated with this application domain.
Definition: AppDomain.cs:280
string [] AppDomainInitializerArguments
Gets or sets the arguments passed to the callback method represented by the T:System....
Provides a collection of static methods that return information about the common language runtime env...
static bool MonitoringIsEnabled
Gets or sets a value that indicates whether CPU and memory monitoring of application domains is enabl...
Definition: AppDomain.cs:504
Assembly Load(AssemblyName assemblyRef, Evidence assemblySecurity)
Loads an T:System.Reflection.Assembly given its T:System.Reflection.AssemblyName.
Definition: AppDomain.cs:1965
Determines whether an assembly belongs to a code group by testing its strong name....
Defines an environment for the objects that are resident inside it and for which a policy can be enfo...
Definition: Context.cs:14
Defines and represents a dynamic assembly.
static Assembly GetEntryAssembly()
Gets the process executable in the default application domain. In other application domains,...
Definition: Assembly.cs:819
string ConfigurationFile
Gets or sets the name of the configuration file for an application domain.
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence)
Defines a dynamic assembly using the specified name, access mode, storage directory,...
Definition: AppDomain.cs:1318
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
Defines a dynamic assembly with the specified name and access mode.
Definition: AppDomain.cs:1207
void SetCachePath(string path)
Establishes the specified directory path as the location where assemblies are shadow copied.
Definition: AppDomain.cs:2406
Assembly Load(string assemblyString)
Loads an T:System.Reflection.Assembly given its display name.
Definition: AppDomain.cs:1882
Evidence Clone()
Returns a duplicate copy of this evidence object.
Definition: Evidence.cs:1310
int ExecuteAssemblyByName(AssemblyName assemblyName, Evidence assemblySecurity, params string[] args)
Executes the assembly given an T:System.Reflection.AssemblyName, using the specified evidence and arg...
Definition: AppDomain.cs:2249
Provides the URL from which a code assembly originates as evidence for policy evaluation....
Definition: Url.cs:10
string ApplicationBase
Gets or sets the name of the directory containing the application.
AssemblyBuilderAccess
Defines the access modes for a dynamic assembly.
string Tag
Gets or sets the tag name of an XML element.
virtual AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
Returns a new or existing application domain.
Provides a base class from which all objects to be used as evidence must derive.
Definition: EvidenceBase.cs:12
void SetShadowCopyPath(string path)
Establishes the specified directory path as the location of assemblies to be shadow copied.
Definition: AppDomain.cs:3603
static Delegate Remove(Delegate source, Delegate value)
Removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
Definition: Delegate.cs:287
static Delegate Combine(Delegate a, Delegate b)
Concatenates the invocation lists of two delegates.
Definition: Delegate.cs:202
void FromXml(SecurityElement e)
Reconstructs a security object with a specified state from an XML encoding.
static AppDomain CurrentDomain
Gets the current application domain for the current T:System.Threading.Thread.
Definition: AppDomain.cs:274
delegate void CrossAppDomainDelegate()
Used by M:System.AppDomain.DoCallBack(System.CrossAppDomainDelegate) for cross-application domain cal...
bool IsHomogenous
Gets a value that indicates whether the current application domain has a set of permissions that is g...
Definition: AppDomain.cs:468
Represents an application domain, which is an isolated environment where applications execute....
Definition: AppDomain.cs:33
bool ContainsKey(TKey key)
Determines whether the T:System.Collections.Generic.Dictionary`2 contains the specified key.
Definition: Dictionary.cs:1303
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
Defines a dynamic assembly using the specified name, access mode, storage directory,...
Definition: AppDomain.cs:1382
new Type GetType()
Gets the type of the current instance.
Definition: AppDomain.cs:4008
The exception that is thrown when an attempt to unload an application domain fails.
void SetShadowCopyFiles()
Turns on shadow copying.
Definition: AppDomain.cs:3612
Cer
Specifies a method's behavior when called within a constrained execution region.
Definition: Cer.cs:5
Represents assembly binding information that can be added to an instance of T:System....
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, bool isSynchronized, IEnumerable< CustomAttributeBuilder > assemblyAttributes)
Defines a dynamic assembly with the specified name, access mode, storage directory,...
Definition: AppDomain.cs:1431
Contains methods to create types of objects locally or remotely, or obtain references to existing rem...
Definition: Activator.cs:21
ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName)
Creates a new instance of a specified COM type. Parameters specify the name of a file that contains a...
Definition: AppDomain.cs:1578
Represents the context for the trust manager to consider when making the decision to run an applicati...
int Compare(object x, object y)
Compares two objects and returns a value indicating whether one is less than, equal to,...
void SetData(string name, object data, IPermission permission)
Assigns the specified value to the specified application domain property, with a specified permission...
Definition: AppDomain.cs:2430
SecurityAction
Specifies the security actions that can be performed using declarative security.
bool? IsCompatibilitySwitchSet(string value)
Gets a nullable Boolean value that indicates whether any compatibility switches are set,...
Definition: AppDomain.cs:2612
Implements a T:System.IO.TextWriter for writing characters to a stream in a particular encoding....
Definition: StreamWriter.cs:15
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
Creates a new instance of the specified type defined in the specified assembly file.
Definition: AppDomain.cs:1795
Provides an event for resolving reflection-only type requests for types that are provided by Windows ...
EventHandler DomainUnload
Occurs when an T:System.AppDomain is about to be unloaded.
Definition: AppDomain.cs:687
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
Definition: MemoryStream.cs:13
object CreateInstanceFromAndUnwrap(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
Creates a new instance of the specified type defined in the specified assembly file,...
Definition: AppDomain.cs:3936
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
bool IsDefaultAppDomain()
Returns a value that indicates whether the application domain is the default application domain for t...
Definition: AppDomain.cs:3949
string Name
Gets or sets the simple name of the assembly. This is usually, but not necessarily,...
Definition: AssemblyName.cs:51
virtual PolicyLevel DomainPolicy
When overridden in a derived class, gets the security policy for the current application domain.
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, bool isSynchronized)
Defines a dynamic assembly using the specified name, access mode, storage directory,...
Definition: AppDomain.cs:1406
Represents a collection that can contain many different types of permissions.
virtual byte [] ToArray()
Writes the stream contents to a byte array, regardless of the P:System.IO.MemoryStream....
static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup info)
Creates a new application domain using the specified name, evidence, and application domain setup inf...
Definition: AppDomain.cs:3152
string ApplyPolicy(string assemblyName)
Returns the assembly display name after policy has been applied.
Definition: AppDomain.cs:1472
UnmanagedType
Identifies how to marshal parameters or fields to unmanaged code.
Definition: UnmanagedType.cs:7
long MonitoringSurvivedMemorySize
Gets the number of bytes that survived the last collection and that are known to be referenced by the...
Definition: AppDomain.cs:560
virtual Evidence ProvideAppDomainEvidence(Evidence inputEvidence)
Provides the application domain evidence for an assembly being loaded.
void ClearShadowCopyPath()
Resets the list of directories containing shadow copied assemblies to the empty string ("").
Definition: AppDomain.cs:2396
Represents the XML object model for encoding security objects. This class cannot be inherited.
ResolveEventHandler TypeResolve
Occurs when the resolution of a type fails.
Definition: AppDomain.cs:596
delegate void EventHandler(object sender, EventArgs e)
Represents the method that will handle an event that has no event data.
void SetAppDomainPolicy(PolicyLevel domainPolicy)
Establishes the security policy level for this application domain.
Definition: AppDomain.cs:2663
virtual HostSecurityManager HostSecurityManager
Gets the host security manager that participates in security decisions for the application domain.
Defines the methods that convert permission object state to and from XML element representation.
virtual void FromXml(SecurityElement et)
Reconstructs a security object with a specified state from an XML encoding.
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable< CustomAttributeBuilder > assemblyAttributes)
Defines a dynamic assembly with the specified name, access mode, and custom attributes.
Definition: AppDomain.cs:1224
AppDomainSetup SetupInformation
Gets the application domain configuration information for this instance.
Definition: AppDomain.cs:431
PrincipalPolicy
Specifies how principal and identity objects should be created for an application domain....
new bool Equals(object other)
Provides COM objects with version-independent access to the inherited M:System.Object....
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
delegate void AssemblyLoadEventHandler(object sender, AssemblyLoadEventArgs args)
Represents the method that handles the E:System.AppDomain.AssemblyLoad event of an T:System....
ObjectHandle CreateInstance(string assemblyName, string typeName, object[] activationAttributes)
Creates a new instance of the specified type defined in the specified assembly. A parameter specifies...
Definition: AppDomain.cs:1637
Defines the underlying structure of all code access permissions.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Assembly Load(string assemblyString, Evidence assemblySecurity)
Loads an T:System.Reflection.Assembly given its display name.
Definition: AppDomain.cs:1986
TimeSpan MonitoringTotalProcessorTime
Gets the total processor time that has been used by all threads while executing in the current applic...
Definition: AppDomain.cs:525
Exposes a method that compares two objects.
Definition: IComparer.cs:8
object CreateInstanceAndUnwrap(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
Creates a new instance of the specified type. Parameters specify the name of the type,...
Definition: AppDomain.cs:3800
static EventHandler< NamespaceResolveEventArgs > ReflectionOnlyNamespaceResolve
Occurs when the resolution of a Windows Metadata file fails in the reflection-only context.
string DynamicDirectory
Gets the directory that the assembly resolver uses to probe for dynamically created assemblies.
Definition: AppDomain.cs:388
AssemblyLoadEventHandler AssemblyLoad
Occurs when an assembly is loaded.
Definition: AppDomain.cs:592
Ability to provide evidence, including the ability to alter the evidence provided by the common langu...
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: Delegate.cs:15
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
void Add(T item)
Adds an object to the end of the T:System.Collections.ObjectModel.Collection`1.
Definition: Collection.cs:204
int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity)
Executes the assembly contained in the specified file, using the specified evidence.
Definition: AppDomain.cs:2025
void SetPrincipalPolicy(PrincipalPolicy policy)
Specifies how principal and identity objects should be attached to a thread if the thread attempts to...
Definition: AppDomain.cs:2714
bool DisallowBindingRedirects
Gets or sets a value that indicates whether an application domain allows assembly binding redirection...
Assembly [] GetAssemblies()
Gets the assemblies that have been loaded into the execution context of this application domain.
Definition: AppDomain.cs:2325
bool??? IsFullyTrusted
Gets a value that indicates whether assemblies that are loaded into the current application domain ex...
Definition: AppDomain.cs:454
Wraps marshal-by-value object references, allowing them to be returned through an indirection.
Definition: ObjectHandle.cs:10
AppDomainManagerInitializationOptions InitializationFlags
Gets the initialization flags for custom application domain managers.
MethodImplOptions
Defines the details of how a method is implemented.
static AppDomain GetDomain()
Returns the current domain in which the current thread is running.
Definition: Thread.cs:1096
ApplicationTrust ApplicationTrust
Gets information describing permissions granted to an application and whether the application has a t...
Definition: AppDomain.cs:372
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
Creates a new instance of the specified type defined in the specified assembly file.
Definition: AppDomain.cs:1834
ObjectHandle CreateComInstanceFrom(string assemblyFile, string typeName, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
Creates a new instance of a specified COM type. Parameters specify the name of a file that contains a...
Definition: AppDomain.cs:1609
Exposes the public members of the T:System.AppDomain class to unmanaged code.
Definition: _AppDomain.cs:17
string PrivateBinPath
Gets or sets the list of directories under the application base directory that are probed for private...
ApplicationTrust ApplicationTrust
Gets or sets an object containing security and trust information.
bool IsApplicationTrustedToRun
Gets or sets a value indicating whether the application has the required permission grants and is tru...
static readonly char PathSeparator
A platform-specific separator character used to separate path strings in environment variables.
Definition: Path.cs:165
Selects a member from a list of candidates, and performs type conversion from actual argument type to...
Definition: Binder.cs:10
static Assembly LoadFrom(string assemblyFile)
Loads an assembly given its file name or path.
Definition: Assembly.cs:369
Defines methods implemented by permission types.
Definition: IPermission.cs:7
Provides data for manifest-based activation of an application. This class cannot be inherited.
delegate void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
Represents the method that will handle the event raised by an exception that is not handled by the ap...
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
AppDomainInitializer AppDomainInitializer
Gets or sets the T:System.AppDomainInitializer delegate, which represents a callback method that is i...
static void RevertAssert()
Causes any previous M:System.Security.CodeAccessPermission.Assert for the current frame to be removed...
static bool IsTransparentProxy(object proxy)
Returns a Boolean value that indicates whether the given object is a transparent proxy or a real obje...
Provides a managed equivalent of an unmanaged host.
int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
Executes the assembly contained in the specified file, using the specified evidence,...
Definition: AppDomain.cs:2107
byte [] GetPublicKey()
Gets the public key of the assembly.
int ExecuteAssemblyByName(string assemblyName)
Executes an assembly given its display name.
Definition: AppDomain.cs:2159
Describes an assembly's unique identity in full.
Definition: AssemblyName.cs:19
Collection< Assembly > ResolvedAssemblies
Gets a collection of assemblies; when the event handler for the E:System.Runtime.InteropServices....
bool ShadowCopyFiles
Gets an indication whether the application domain is configured to shadow copy files.
Definition: AppDomain.cs:335
The exception that is thrown when one of the arguments provided to a method is not valid.
static object CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture)
Creates an instance of the specified type using the constructor that best matches the specified param...
Definition: Activator.cs:57
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
ApplicationTrust(ApplicationIdentity applicationIdentity)
Initializes a new instance of the T:System.Security.Policy.ApplicationTrust class with an T:System....
The exception that is thrown when an attempt to access a file that does not exist on disk fails.
UnhandledExceptionEventHandler UnhandledException
Occurs when an exception is not caught.
Definition: AppDomain.cs:711
static AppDomain CreateDomain(string friendlyName)
Creates a new application domain with the specified name.
Definition: AppDomain.cs:2782
int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity, string[] args)
Executes the assembly contained in the specified file, using the specified evidence and arguments.
Definition: AppDomain.cs:2048
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
object CreateInstanceAndUnwrap(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
Creates a new instance of the specified type defined in the specified assembly, specifying whether th...
Definition: AppDomain.cs:3829
Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore)
Loads the T:System.Reflection.Assembly with a common object file format (COFF) based image containing...
Definition: AppDomain.cs:1917
static IEnumerable< string > ResolveNamespace(string namespaceName, IEnumerable< string > packageGraphFilePaths)
Locates the Windows Metadata files for the specified namespace, given the specified locations to sear...
Identifies the version of the .NET Framework that a particular assembly was compiled against.
Defines the set of information that constitutes input to security policy decisions....
Definition: Evidence.cs:17
static AppDomain CreateDomain(string friendlyName, Evidence securityInfo)
Creates a new application domain with the given name using the supplied evidence.
Definition: AppDomain.cs:2747
PermissionSet PermissionSet
Gets the permission set of a sandboxed application domain.
Definition: AppDomain.cs:436
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
AppDomainManager DomainManager
Gets the domain manager that was provided by the host when the application domain was initialized.
Definition: AppDomain.cs:245
virtual HostSecurityManagerOptions Flags
Gets the flag representing the security policy components of concern to the host.
Provides the ability to uniquely identify a manifest-activated application. This class cannot be inhe...
ResolveEventHandler ReflectionOnlyAssemblyResolve
Occurs when the resolution of an assembly fails in the reflection-only context.
Definition: AppDomain.cs:659
Specifies that the class can be serialized.
delegate void AppDomainInitializer(string[] args)
Represents the callback method to invoke when the application domain is initialized.
object CreateInstanceAndUnwrap(string assemblyName, string typeName)
Creates a new instance of the specified type. Parameters specify the assembly where the type is defin...
Definition: AppDomain.cs:3747
void SetData(string name, object data)
Assigns the specified value to the specified application domain property.
Definition: AppDomain.cs:2416
static Encoding UTF8
Gets an encoding for the UTF-8 format.
Definition: Encoding.cs:1023
static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles)
Creates a new application domain with the given name, using evidence, application base path,...
Definition: AppDomain.cs:2761
The exception that is thrown when a method call is invalid for the object's current state.
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
Defines a dynamic assembly using the specified name, access mode, evidence, and permission requests.
Definition: AppDomain.cs:1360
static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Gets the T:System.Type with the specified name, specifying whether to throw an exception if the type ...
Definition: Type.cs:853
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
object GetData(string name)
Gets the value stored in the current application domain for the specified name.
Definition: AppDomain.cs:2542
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
Consistency
Specifies a reliability contract.
Definition: Consistency.cs:5
int ExecuteAssemblyByName(AssemblyName assemblyName, params string[] args)
Executes the assembly given an T:System.Reflection.AssemblyName, using the specified arguments.
Definition: AppDomain.cs:2274
ObjectHandle CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
Creates a new instance of the specified type defined in the specified assembly. Parameters specify a ...
Definition: AppDomain.cs:1747
Provides the main access point for classes interacting with the security system. This class cannot be...
virtual PermissionSet Copy()
Creates a copy of the T:System.Security.PermissionSet.
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
object Unwrap()
Returns the wrapped object.
Definition: ObjectHandle.cs:27
object CreateInstanceFromAndUnwrap(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
Creates a new instance of the specified type defined in the specified assembly file.
Definition: AppDomain.cs:3906
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
Controls the ability to access files and folders. This class cannot be inherited.
AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
Defines a dynamic assembly using the specified name, access mode, and permission requests.
Definition: AppDomain.cs:1299
EventHandler ProcessExit
Occurs when the default application domain's parent process exits.
Definition: AppDomain.cs:663
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
SecurityPermissionFlag
Specifies access flags for the security permission object.
static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer adInit, string[] adInitArgs)
Creates a new application domain with the given name, using evidence, application base path,...
Definition: AppDomain.cs:3227
void DoCallBack(CrossAppDomainDelegate callBackDelegate)
Executes the code in another application domain that is identified by the specified delegate.
Definition: AppDomain.cs:2732
Provides several methods for using and publishing remoted objects and proxies. This class cannot be i...
object CreateInstanceFromAndUnwrap(string assemblyName, string typeName, object[] activationAttributes)
Creates a new instance of the specified type defined in the specified assembly file.
Definition: AppDomain.cs:3875
Represents a generic principal.
override void Flush()
Clears all buffers for the current writer and causes any buffered data to be written to the underlyin...
Assembly [] ReflectionOnlyGetAssemblies()
Returns the assemblies that have been loaded into the reflection-only context of the application doma...
Definition: AppDomain.cs:2333
static int GetCurrentThreadId()
Gets the current thread identifier.
delegate Assembly ResolveEventHandler(object sender, ResolveEventArgs args)
Represents a method that handles the E:System.AppDomain.TypeResolve, E:System.AppDomain....
ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName)
Creates a new instance of the specified type defined in the specified assembly file.
Definition: AppDomain.cs:1542
The exception that is thrown when policy forbids code to run.
The exception that is thrown when a requested method or operation is not implemented.
The exception that is thrown when a security error is detected.
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
byte [] GetPublicKeyToken()
Gets the public key token, which is the last 8 bytes of the SHA-1 hash of the public key under which ...
static IEnumerable< Attribute > GetCustomAttributes(this Assembly element)
Retrieves a collection of custom attributes that are applied to a specified assembly.
Assembly Load(byte[] rawAssembly)
Loads the T:System.Reflection.Assembly with a common object file format (COFF) based image containing...
Definition: AppDomain.cs:1899
string Name
Gets the simple name of the current T:System.Security.Policy.StrongName.
Definition: StrongName.cs:32
AssemblyHashAlgorithm
Specifies all the hash algorithms used for hashing files and for generating the strong name.
object CreateInstanceFromAndUnwrap(string assemblyName, string typeName)
Creates a new instance of the specified type defined in the specified assembly file.
Definition: AppDomain.cs:3851
Attribute can be applied to a delegate.
int ExecuteAssembly(string assemblyFile, string[] args)
Executes the assembly contained in the specified file, using the specified arguments.
Definition: AppDomain.cs:2077
Allows the control and customization of security behavior for application domains.
void SetPublicKeyToken(byte[] publicKeyToken)
Sets the public key token, which is the last 8 bytes of the SHA-1 hash of the public key under which ...
int ExecuteAssembly(string assemblyFile, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
Executes the assembly contained in the specified file, using the specified arguments,...
Definition: AppDomain.cs:2138
Provides a set of static methods and properties that provide support for compilers....
ResolveEventHandler AssemblyResolve
Occurs when the resolution of an assembly fails.
Definition: AppDomain.cs:638
Provides data for the E:System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMetadata....
Enables access to objects across application domain boundaries in applications that support remoting.
Creates and controls a thread, sets its priority, and gets its status.
Definition: Thread.cs:18
PolicyStatement DefaultGrantSet
Gets or sets the policy statement defining the default grant set.