Add feature define for multiple appdomains.
[mono.git] / mcs / class / referencesource / mscorlib / system / activator.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 ////////////////////////////////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////////////////////////////////
8 //
9 // Activator is an object that contains the Activation (CreateInstance/New) 
10 //  methods for late bound support.
11 //
12 // 
13 // 
14 //
15 namespace System {
16
17     using System;
18     using System.Reflection;
19     using System.Runtime.Remoting;
20 #if FEATURE_REMOTING    
21     using System.Runtime.Remoting.Activation;
22 //    using Message = System.Runtime.Remoting.Messaging.Message;
23 #endif
24     using System.Security;
25     using CultureInfo = System.Globalization.CultureInfo;
26     using Evidence = System.Security.Policy.Evidence;
27     using StackCrawlMark = System.Threading.StackCrawlMark;
28     using System.Runtime.InteropServices;
29     using System.Runtime.CompilerServices;
30     using System.Security.Permissions;
31     using AssemblyHashAlgorithm = System.Configuration.Assemblies.AssemblyHashAlgorithm;
32     using System.Runtime.Versioning;
33     using System.Diagnostics.Contracts;
34
35     // Only statics, does not need to be marked with the serializable attribute
36     [ClassInterface(ClassInterfaceType.None)]
37     [ComDefaultInterface(typeof(_Activator))]
38 [System.Runtime.InteropServices.ComVisible(true)]
39     public sealed class Activator : _Activator
40     {
41         internal const int LookupMask                 = 0x000000FF;
42         internal const BindingFlags ConLookup         = (BindingFlags) (BindingFlags.Instance | BindingFlags.Public);
43         internal const BindingFlags ConstructorDefault= BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance;
44
45         // This class only contains statics, so hide the worthless constructor
46         private Activator()
47         {
48         }
49
50         // CreateInstance
51         // The following methods will create a new instance of an Object
52         // Full Binding Support
53         // For all of these methods we need to get the underlying RuntimeType and
54         //  call the Impl version.
55         static public Object CreateInstance(Type type,
56                                             BindingFlags bindingAttr,
57                                             Binder binder,
58                                             Object[] args,
59                                             CultureInfo culture) 
60         {
61             return CreateInstance(type, bindingAttr, binder, args, culture, null);
62         }
63
64         [System.Security.SecuritySafeCritical]  // auto-generated
65         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
66         static public Object CreateInstance(Type type,
67                                             BindingFlags bindingAttr,
68                                             Binder binder,
69                                             Object[] args,
70                                             CultureInfo culture,
71                                             Object[] activationAttributes)
72         {
73             if ((object)type == null)
74                 throw new ArgumentNullException("type");
75             Contract.EndContractBlock();
76 #if !FULL_AOT_RUNTIME
77             if (type is System.Reflection.Emit.TypeBuilder)
78                 throw new NotSupportedException(Environment.GetResourceString("NotSupported_CreateInstanceWithTypeBuilder"));
79 #endif
80             // If they didn't specify a lookup, then we will provide the default lookup.
81             if ((bindingAttr & (BindingFlags) LookupMask) == 0)
82                 bindingAttr |= Activator.ConstructorDefault;
83
84             if (activationAttributes != null && activationAttributes.Length > 0){
85                 // If type does not derive from MBR
86                 // throw notsupportedexception
87 #if FEATURE_REMOTING                
88                 if(type.IsMarshalByRef){
89                     // The fix below is preventative.
90                     //
91                     if(!(type.IsContextful)){
92                         if(activationAttributes.Length > 1 || !(activationAttributes[0] is UrlAttribute))
93                            throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonUrlAttrOnMBR"));
94                     }
95                 }
96                 else
97 #endif                    
98                     throw new NotSupportedException(Environment.GetResourceString("NotSupported_ActivAttrOnNonMBR" ));
99             }
100
101             RuntimeType rt = type.UnderlyingSystemType as RuntimeType;
102
103             if (rt == null)
104                 throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"type");
105
106             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
107             return rt.CreateInstanceImpl(bindingAttr,binder,args,culture,activationAttributes, ref stackMark);
108         }
109
110         static public Object CreateInstance(Type type, params Object[] args)
111         {
112             return CreateInstance(type,
113                                   Activator.ConstructorDefault,
114                                   null,
115                                   args,
116                                   null,
117                                   null);
118         }
119
120         static public Object CreateInstance(Type type,
121                                             Object[] args,
122                                             Object[] activationAttributes)
123         {
124              return CreateInstance(type,
125                                    Activator.ConstructorDefault,
126                                    null,
127                                    args,
128                                    null,
129                                    activationAttributes);
130         }
131         
132         static public Object CreateInstance(Type type)
133         {
134             return Activator.CreateInstance(type, false);
135         }
136
137         /*
138          * Create an instance using the name of type and the assembly where it exists. This allows
139          * types to be created remotely without having to load the type locally.
140          */
141
142         [System.Security.SecuritySafeCritical]  // auto-generated
143         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
144         static public ObjectHandle CreateInstance(String assemblyName,
145                                                   String typeName)
146         {
147 #if MONO
148             if(assemblyName == null)
149               assemblyName = Assembly.GetCallingAssembly ().GetName ().Name;
150 #endif
151             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
152             return CreateInstance(assemblyName,
153                                   typeName, 
154                                   false,
155                                   Activator.ConstructorDefault,
156                                   null,
157                                   null,
158                                   null,
159                                   null,
160                                   null,
161                                   ref stackMark);
162         }
163
164         [System.Security.SecuritySafeCritical]  // auto-generated
165         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable                                                  
166         static public ObjectHandle CreateInstance(String assemblyName,
167                                                   String typeName,
168                                                   Object[] activationAttributes)
169                                                   
170         {
171 #if MONO
172             if(assemblyName == null)
173               assemblyName = Assembly.GetCallingAssembly ().GetName ().Name;
174 #endif
175             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
176             return CreateInstance(assemblyName,
177                                   typeName, 
178                                   false,
179                                   Activator.ConstructorDefault,
180                                   null,
181                                   null,
182                                   null,
183                                   activationAttributes,
184                                   null,
185                                   ref stackMark);
186         }
187             
188         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
189         static public Object CreateInstance(Type type, bool nonPublic)
190         {
191             if ((object)type == null)
192                 throw new ArgumentNullException("type");
193             Contract.EndContractBlock();
194
195             RuntimeType rt = type.UnderlyingSystemType as RuntimeType;
196
197             if (rt == null)
198                 throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "type");
199
200             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
201             return rt.CreateInstanceDefaultCtor(!nonPublic, false, true, ref stackMark);
202         }
203
204         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
205         static public T CreateInstance<T>()
206         {
207             RuntimeType rt = typeof(T) as RuntimeType;
208
209             // This is a hack to maintain compatibility with V2. Without this we would throw a NotSupportedException for void[].
210             // Array, Ref, and Pointer types don't have default constructors.
211             if (rt.HasElementType)
212                 throw new MissingMethodException(Environment.GetResourceString("Arg_NoDefCTor"));
213
214             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
215
216             // Skip the CreateInstanceCheckThis call to avoid perf cost and to maintain compatibility with V2 (throwing the same exceptions).
217 #if FEATURE_CORECLR
218             // In SL2/3 CreateInstance<T> doesn't do any security checks. This would mean that Assembly B can create instances of an internal
219             // type in Assembly A upon A's request:
220             //      TypeInAssemblyA.DoWork() { AssemblyB.Create<InternalTypeInAssemblyA>();}
221             //      TypeInAssemblyB.Create<T>() {return new T();}
222             // This violates type safety but we saw multiple user apps that have put a dependency on it. So for compatability we allow this if
223             // the SL app was built against SL2/3.
224             // Note that in SL2/3 it is possible for app code to instantiate public transparent types with public critical default constructors.
225             // Fortunately we don't have such types in out platform assemblies.
226             if (CompatibilitySwitches.IsAppEarlierThanSilverlight4 ||
227                 CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
228                 return (T)rt.CreateInstanceSlow(true /*publicOnly*/, true /*skipCheckThis*/, false /*fillCache*/, ref stackMark);
229             else
230 #endif // FEATURE_CORECLR
231             return (T)rt.CreateInstanceDefaultCtor(true /*publicOnly*/, true /*skipCheckThis*/, true /*fillCache*/, ref stackMark);
232         }
233
234         [ResourceExposure(ResourceScope.Machine)]
235         [ResourceConsumption(ResourceScope.Machine)]
236         static public ObjectHandle CreateInstanceFrom(String assemblyFile,
237                                                       String typeName)
238                                          
239         {
240             return CreateInstanceFrom(assemblyFile, typeName, null);
241         }
242
243         [ResourceExposure(ResourceScope.Machine)]
244         [ResourceConsumption(ResourceScope.Machine)]
245         static public ObjectHandle CreateInstanceFrom(String assemblyFile,
246                                                       String typeName,
247                                                       Object[] activationAttributes)
248                                          
249         {
250             return CreateInstanceFrom(assemblyFile,
251                                       typeName, 
252                                       false,
253                                       Activator.ConstructorDefault,
254                                       null,
255                                       null,
256                                       null,
257                                       activationAttributes);
258         }
259                                   
260         [System.Security.SecuritySafeCritical]  // auto-generated
261         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
262         [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.")]
263         static public ObjectHandle CreateInstance(String assemblyName, 
264                                                   String typeName, 
265                                                   bool ignoreCase,
266                                                   BindingFlags bindingAttr, 
267                                                   Binder binder,
268                                                   Object[] args,
269                                                   CultureInfo culture,
270                                                   Object[] activationAttributes,
271                                                   Evidence securityInfo)
272         {
273 #if MONO
274             if(assemblyName == null)
275               assemblyName = Assembly.GetCallingAssembly ().GetName ().Name;
276 #endif
277             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
278             return CreateInstance(assemblyName,
279                                   typeName,
280                                   ignoreCase,
281                                   bindingAttr,
282                                   binder,
283                                   args,
284                                   culture,
285                                   activationAttributes,
286                                   securityInfo,
287                                   ref stackMark);
288         }
289
290         [SecuritySafeCritical]
291         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
292         public static ObjectHandle CreateInstance(string assemblyName,
293                                                   string typeName,
294                                                   bool ignoreCase,
295                                                   BindingFlags bindingAttr,
296                                                   Binder binder,
297                                                   object[] args,
298                                                   CultureInfo culture,
299                                                   object[] activationAttributes)
300         {
301 #if MONO
302             if(assemblyName == null)
303               assemblyName = Assembly.GetCallingAssembly ().GetName ().Name;
304 #endif
305             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
306             return CreateInstance(assemblyName,
307                                   typeName,
308                                   ignoreCase,
309                                   bindingAttr,
310                                   binder,
311                                   args,
312                                   culture,
313                                   activationAttributes,
314                                   null,
315                                   ref stackMark);
316         }
317
318         [System.Security.SecurityCritical]  // auto-generated
319         static internal ObjectHandle CreateInstance(String assemblyString, 
320                                                     String typeName, 
321                                                     bool ignoreCase,
322                                                     BindingFlags bindingAttr, 
323                                                     Binder binder,
324                                                     Object[] args,
325                                                     CultureInfo culture,
326                                                     Object[] activationAttributes,
327                                                     Evidence securityInfo,
328                                                     ref StackCrawlMark stackMark)
329         {
330 #if FEATURE_CAS_POLICY
331             if (securityInfo != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
332             {
333                 throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
334             }
335 #endif // FEATURE_CAS_POLICY
336             Type type = null;
337             Assembly assembly = null;
338             if (assemblyString == null) {
339                 assembly = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
340             } else {
341                 RuntimeAssembly assemblyFromResolveEvent;
342                 AssemblyName assemblyName = RuntimeAssembly.CreateAssemblyName(assemblyString, false /*forIntrospection*/, out assemblyFromResolveEvent);
343                 if (assemblyFromResolveEvent != null) {
344                     // Assembly was resolved via AssemblyResolve event
345                     assembly = assemblyFromResolveEvent;
346                 } else if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime) {
347                     // WinRT type - we have to use Type.GetType
348                     type = Type.GetType(typeName + ", " + assemblyString, true /*throwOnError*/, ignoreCase);
349                 } else {
350                     // Classic managed type
351                     assembly = RuntimeAssembly.InternalLoadAssemblyName(
352                         assemblyName, securityInfo, null, ref stackMark,
353                         true /*thrownOnFileNotFound*/, false /*forIntrospection*/, false /*suppressSecurityChecks*/);
354                 }
355             }
356
357             if (type == null) {
358                 // It's classic managed type (not WinRT type)
359                 Log(assembly != null, "CreateInstance:: ", "Loaded " + assembly.FullName, "Failed to Load: " + assemblyString);
360                 if(assembly == null) return null;
361
362                 type = assembly.GetType(typeName, true /*throwOnError*/, ignoreCase);
363             }
364             
365             Object o = Activator.CreateInstance(type,
366                                                 bindingAttr,
367                                                 binder,
368                                                 args,
369                                                 culture,
370                                                 activationAttributes);
371
372             Log(o != null, "CreateInstance:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
373             if(o == null)
374                 return null;
375             else {
376                 ObjectHandle Handle = new ObjectHandle(o);
377                 return Handle;
378             }
379         }
380
381         [ResourceExposure(ResourceScope.Machine)]
382         [ResourceConsumption(ResourceScope.Machine)]
383         [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.")]
384         static public ObjectHandle CreateInstanceFrom(String assemblyFile,
385                                                       String typeName, 
386                                                       bool ignoreCase,
387                                                       BindingFlags bindingAttr, 
388                                                       Binder binder,
389                                                       Object[] args,
390                                                       CultureInfo culture,
391                                                       Object[] activationAttributes,
392                                                       Evidence securityInfo)
393                                                
394         {
395 #if FEATURE_CAS_POLICY
396             if (securityInfo != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
397             {
398                 throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
399             }
400 #endif // FEATURE_CAS_POLICY
401
402             return CreateInstanceFromInternal(assemblyFile,
403                                               typeName,
404                                               ignoreCase,
405                                               bindingAttr,
406                                               binder,
407                                               args,
408                                               culture,
409                                               activationAttributes,
410                                               securityInfo);
411         }
412
413         [ResourceExposure(ResourceScope.Machine)]
414         [ResourceConsumption(ResourceScope.Machine)]
415         public static ObjectHandle CreateInstanceFrom(string assemblyFile,
416                                                       string typeName,
417                                                       bool ignoreCase,
418                                                       BindingFlags bindingAttr,
419                                                       Binder binder,
420                                                       object[] args,
421                                                       CultureInfo culture,
422                                                       object[] activationAttributes)
423         {
424             return CreateInstanceFromInternal(assemblyFile,
425                                               typeName,
426                                               ignoreCase,
427                                               bindingAttr,
428                                               binder,
429                                               args,
430                                               culture,
431                                               activationAttributes,
432                                               null);
433         }
434
435         [ResourceExposure(ResourceScope.Machine)]
436         [ResourceConsumption(ResourceScope.Machine)]
437         private static ObjectHandle CreateInstanceFromInternal(String assemblyFile,
438                                                                String typeName, 
439                                                                bool ignoreCase,
440                                                                BindingFlags bindingAttr, 
441                                                                Binder binder,
442                                                                Object[] args,
443                                                                CultureInfo culture,
444                                                                Object[] activationAttributes,
445                                                                Evidence securityInfo)
446         {
447 #if FEATURE_CAS_POLICY
448             Contract.Assert(AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled || securityInfo == null);
449 #endif // FEATURE_CAS_POLICY
450
451 #pragma warning disable 618
452             Assembly assembly = Assembly.LoadFrom(assemblyFile, securityInfo);
453 #pragma warning restore 618
454             Type t = assembly.GetType(typeName, true, ignoreCase);
455             
456             Object o = Activator.CreateInstance(t,
457                                                 bindingAttr,
458                                                 binder,
459                                                 args,
460                                                 culture,
461                                                 activationAttributes);
462
463             Log(o != null, "CreateInstanceFrom:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
464             if(o == null)
465                 return null;
466             else {
467                 ObjectHandle Handle = new ObjectHandle(o);
468                 return Handle;
469             }
470         }
471
472         //
473         // This API is designed to be used when a host needs to execute code in an AppDomain
474         // with restricted security permissions. In that case, we demand in the client domain
475         // and assert in the server domain because the server domain might not be trusted enough
476         // to pass the security checks when activating the type.
477         //
478
479         [System.Security.SecurityCritical]  // auto-generated_required
480         public static ObjectHandle CreateInstance (AppDomain domain, string assemblyName, string typeName) {
481             if (domain == null)
482                 throw new ArgumentNullException("domain");
483             Contract.EndContractBlock();
484             return domain.InternalCreateInstanceWithNoSecurity(assemblyName, typeName);
485         }
486
487         [System.Security.SecurityCritical]  // auto-generated_required
488         [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.")]
489         public static ObjectHandle CreateInstance (AppDomain domain,
490                                                    string assemblyName,
491                                                    string typeName,
492                                                    bool ignoreCase,
493                                                    BindingFlags bindingAttr,
494                                                    Binder binder,
495                                                    Object[] args,
496                                                    CultureInfo culture,
497                                                    Object[] activationAttributes,
498                                                    Evidence securityAttributes) {
499             if (domain == null)
500                 throw new ArgumentNullException("domain");
501             Contract.EndContractBlock();
502
503 #if FEATURE_CAS_POLICY
504             if (securityAttributes != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
505             {
506                 throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
507             }
508 #endif // FEATURE_CAS_POLICY
509
510             return domain.InternalCreateInstanceWithNoSecurity(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes);
511         }
512
513         [SecurityCritical]
514         public static ObjectHandle CreateInstance(AppDomain domain,
515                                                   string assemblyName,
516                                                   string typeName,
517                                                   bool ignoreCase,
518                                                   BindingFlags bindingAttr,
519                                                   Binder binder,
520                                                   object[] args,
521                                                   CultureInfo culture,
522                                                   object[] activationAttributes)
523         {
524             if (domain == null)
525                 throw new ArgumentNullException("domain");
526             Contract.EndContractBlock();
527
528             return domain.InternalCreateInstanceWithNoSecurity(assemblyName,
529                                                                typeName,
530                                                                ignoreCase,
531                                                                bindingAttr,
532                                                                binder,
533                                                                args,
534                                                                culture,
535                                                                activationAttributes,
536                                                                null);
537         }
538
539         //
540         // This API is designed to be used when a host needs to execute code in an AppDomain
541         // with restricted security permissions. In that case, we demand in the client domain
542         // and assert in the server domain because the server domain might not be trusted enough
543         // to pass the security checks when activating the type.
544         //
545
546         [System.Security.SecurityCritical]  // auto-generated_required
547         [ResourceExposure(ResourceScope.Machine)]
548         [ResourceConsumption(ResourceScope.Machine)]
549         public static ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName) {
550             if (domain == null)
551                 throw new ArgumentNullException("domain");
552             Contract.EndContractBlock();
553             return domain.InternalCreateInstanceFromWithNoSecurity(assemblyFile, typeName);
554         }
555
556         [System.Security.SecurityCritical]  // auto-generated_required
557         [ResourceExposure(ResourceScope.Machine)]
558         [ResourceConsumption(ResourceScope.Machine)]
559         [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.")]
560         public static ObjectHandle CreateInstanceFrom (AppDomain domain,
561                                                        string assemblyFile,
562                                                        string typeName,
563                                                        bool ignoreCase,
564                                                        BindingFlags bindingAttr,
565                                                        Binder binder,
566                                                        Object[] args,
567                                                        CultureInfo culture,
568                                                        Object[] activationAttributes,
569                                                        Evidence securityAttributes) {
570             if (domain == null)
571                 throw new ArgumentNullException("domain");
572             Contract.EndContractBlock();
573
574 #if FEATURE_CAS_POLICY
575             if (securityAttributes != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
576             {
577                 throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
578             }
579 #endif // FEATURE_CAS_POLICY
580
581             return domain.InternalCreateInstanceFromWithNoSecurity(assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes);
582         }
583
584         [SecurityCritical]
585         [ResourceExposure(ResourceScope.Machine)]
586         [ResourceConsumption(ResourceScope.Machine)]
587         public static ObjectHandle CreateInstanceFrom(AppDomain domain,
588                                                       string assemblyFile,
589                                                       string typeName,
590                                                       bool ignoreCase,
591                                                       BindingFlags bindingAttr,
592                                                       Binder binder,
593                                                       object[] args,
594                                                       CultureInfo culture,
595                                                       object[] activationAttributes)
596         {
597             if (domain == null)
598                 throw new ArgumentNullException("domain");
599             Contract.EndContractBlock();
600
601             return domain.InternalCreateInstanceFromWithNoSecurity(assemblyFile,
602                                                                    typeName,
603                                                                    ignoreCase,
604                                                                    bindingAttr,
605                                                                    binder,
606                                                                    args,
607                                                                    culture,
608                                                                    activationAttributes,
609                                                                    null);
610         }
611 #if FEATURE_COMINTEROP || MONO_COM || MOBILE_LEGACY
612
613 #if FEATURE_CLICKONCE || MOBILE_LEGACY
614 #if FEATURE_CLICKONCE || MONO_FEATURE_MULTIPLE_APPDOMAINS
615         [System.Security.SecuritySafeCritical]  // auto-generated
616         public static ObjectHandle CreateInstance (ActivationContext activationContext) {
617             AppDomainManager domainManager = AppDomain.CurrentDomain.DomainManager;
618             if (domainManager == null)
619                 domainManager = new AppDomainManager();
620
621             return domainManager.ApplicationActivator.CreateInstance(activationContext);
622         }
623
624         [System.Security.SecuritySafeCritical]  // auto-generated
625         public static ObjectHandle CreateInstance (ActivationContext activationContext, string[] activationCustomData) {
626             AppDomainManager domainManager = AppDomain.CurrentDomain.DomainManager;
627             if (domainManager == null)
628                 domainManager = new AppDomainManager();
629
630             return domainManager.ApplicationActivator.CreateInstance(activationContext, activationCustomData);
631         }
632 #else
633         [Obsolete ("Activator.CreateInstance (ActivationContext) is not supported on this platform.", true)]
634         public static ObjectHandle CreateInstance (ActivationContext activationContext) {
635             throw new PlatformNotSupportedException ("Activator.CreateInstance (ActivationContext) is not supported on this platform.");
636         }
637
638         [Obsolete ("Activator.CreateInstance (ActivationContext, string[]) is not supported on this platform.", true)]
639         public static ObjectHandle CreateInstance (ActivationContext activationContext, string[] activationCustomData) {
640             throw new PlatformNotSupportedException ("Activator.CreateInstance (ActivationContext) is not supported on this platform.");
641         }
642 #endif
643 #endif // FEATURE_CLICKONCE
644
645         [ResourceExposure(ResourceScope.Machine)]
646         [ResourceConsumption(ResourceScope.Machine)]
647         public static ObjectHandle CreateComInstanceFrom(String assemblyName,
648                                                          String typeName)                                         
649         {
650             return CreateComInstanceFrom(assemblyName,
651                                          typeName,
652                                          null,
653                                          AssemblyHashAlgorithm.None);
654                                          
655         }
656                                          
657         [ResourceExposure(ResourceScope.Machine)]
658         [ResourceConsumption(ResourceScope.Machine)]                             
659         public static ObjectHandle CreateComInstanceFrom(String assemblyName,
660                                                          String typeName,
661                                                          byte[] hashValue, 
662                                                          AssemblyHashAlgorithm hashAlgorithm)
663         {
664             Assembly assembly = Assembly.LoadFrom(assemblyName, hashValue, hashAlgorithm);
665
666             Type t = assembly.GetType(typeName, true, false);
667
668             Object[] Attr = t.GetCustomAttributes(typeof(ComVisibleAttribute),false);
669             if (Attr.Length > 0)
670             {
671                 if (((ComVisibleAttribute)Attr[0]).Value == false)
672                     throw new TypeLoadException(Environment.GetResourceString( "Argument_TypeMustBeVisibleFromCom" ));
673             }
674
675             Log(assembly != null, "CreateInstance:: ", "Loaded " + assembly.FullName, "Failed to Load: " + assemblyName);
676
677             if(assembly == null) return null;
678
679   
680             Object o = Activator.CreateInstance(t,
681                                                 Activator.ConstructorDefault,
682                                                 null,
683                                                 null,
684                                                 null,
685                                                 null);
686
687             Log(o != null, "CreateInstance:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
688             if(o == null)
689                 return null;
690             else {
691                 ObjectHandle Handle = new ObjectHandle(o);
692                 return Handle;
693             }
694         }
695 #endif // FEATURE_COMINTEROP                                  
696
697 #if FEATURE_REMOTING || MOBILE_LEGACY
698         //  This method is a helper method and delegates to the remoting 
699         //  services to do the actual work. 
700         [System.Security.SecurityCritical]  // auto-generated_required
701         static public Object GetObject(Type type, String url)
702         {
703             return GetObject(type, url, null);
704         }
705         
706         //  This method is a helper method and delegates to the remoting 
707         //  services to do the actual work. 
708         [System.Security.SecurityCritical]  // auto-generated_required
709         static public Object GetObject(Type type, String url, Object state)
710         {
711             if (type == null)
712                 throw new ArgumentNullException("type");
713             Contract.EndContractBlock();
714             return RemotingServices.Connect(type, url, state);
715         }
716 #endif
717
718         [System.Diagnostics.Conditional("_DEBUG")]
719         private static void Log(bool test, string title, string success, string failure)
720         {
721 #if FEATURE_REMOTING
722             if(test)
723                 BCLDebug.Trace("REMOTE", "{0}{1}", title, success);
724             else
725                 BCLDebug.Trace("REMOTE", "{0}{1}", title, failure);
726 #endif            
727         }
728
729 #if !FEATURE_CORECLR
730         void _Activator.GetTypeInfoCount(out uint pcTInfo)
731         {
732             throw new NotImplementedException();
733         }
734
735         void _Activator.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
736         {
737             throw new NotImplementedException();
738         }
739
740         void _Activator.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
741         {
742             throw new NotImplementedException();
743         }
744
745         // If you implement this method, make sure to include _Activator.Invoke in VM\DangerousAPIs.h and
746         // include _Activator in SystemDomain::IsReflectionInvocationMethod in AppDomain.cpp.
747         void _Activator.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
748         {
749             throw new NotImplementedException();
750         }
751 #endif
752     }
753 }
754