Example #1
0
        /// <summary>
        /// Processes the provided assembly.
        /// </summary>
        /// <param name="assembly">The assembly to process.</param>
        private void ProcessAssembly(Assembly assembly)
        {
            string assemblyName = assembly.GetName().Name;

            if (this.logger.IsVerbose3)
            {
                this.logger.Verbose3("Processing assembly {0}", assemblyName);
            }

#if !NETSTANDARD
            // If the assembly is loaded for reflection only avoid processing it.
            if (assembly.ReflectionOnly)
            {
                return;
            }
#endif

            // Don't bother re-processing an assembly we've already scanned
            lock (this.processedAssemblies)
            {
                if (!this.processedAssemblies.Add(assembly))
                {
                    return;
                }
            }

            // If the assembly does not reference Orleans, avoid generating code for it.
            if (TypeUtils.IsOrleansOrReferencesOrleans(assembly))
            {
                // Code generation occurs in a self-contained assembly, so invoke it separately.
                CodeGeneratorManager.GenerateAndCacheCodeForAssembly(assembly);
            }

            // Process each type in the assembly.
            var assemblyTypes = TypeUtils.GetDefinedTypes(assembly, this.logger).ToArray();

            // Process each type in the assembly.
            foreach (TypeInfo typeInfo in assemblyTypes)
            {
                try
                {
                    var    type     = typeInfo.AsType();
                    string typeName = typeInfo.FullName;
                    if (this.logger.IsVerbose3)
                    {
                        this.logger.Verbose3("Processing type {0}", typeName);
                    }

                    SerializationManager.FindSerializationInfo(type);

                    this.typeCache.FindSupportClasses(type);
                }
                catch (Exception exception)
                {
                    this.logger.Error(ErrorCode.SerMgr_TypeRegistrationFailure, "Failed to load type " + typeInfo.FullName + " in assembly " + assembly.FullName + ".", exception);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Create a new criterion that filters assemblies by predicate.
        /// </summary>
        /// <param name="typePredicate">A predicate which accepts a reflection-only type as an argument. If this predicate returns true, the assembly that provides the specified type will loaded and further inspection of the assembly with halt. If this predicate returns false, the predicate may provide a complaint explaining why the assembly does not meet the criterion described by the predicate.</param>
        /// <param name="defaultComplaints">If no predicate provides a complaint, then these default complaints are logged instead.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">assemblyPredicate is null.</exception>
        internal static AssemblyLoaderReflectionCriterion NewCriterion(TypePredicate typePredicate, IEnumerable <string> defaultComplaints)
        {
            CheckComplaintQuality(defaultComplaints);

            return(NewCriterion(
                       (Assembly assembly, out IEnumerable <string> assemblyComplaints) =>
            {
                Type[] types;
                try
                {
                    types = TypeUtils.GetDefinedTypes(assembly).ToArray();
                }
                catch (ReflectionTypeLoadException e)
                {
                    if (InterceptReflectionTypeLoadException(e, out assemblyComplaints))
                    {
                        return false;
                    }

                    // the default representation of a ReflectionTypeLoadException isn't very helpful
                    // to the user, so we flatten it into an AggregateException.
                    throw e.Flatten();
                }

                List <string> complaints = new List <string>();
                foreach (var type in types)
                {
                    IEnumerable <string> typeComplaints;
                    if (typePredicate(type, out typeComplaints))
                    {
                        //  we found a match! load the assembly.
                        assemblyComplaints = null;
                        return true;
                    }
                    if (typeComplaints != null)
                    {
                        complaints.AddRange(typeComplaints);
                    }
                }

                if (complaints.Count == 0)
                {
                    complaints.AddRange(defaultComplaints);
                }
                assemblyComplaints = complaints;
                return false;
            }));
        }
Example #3
0
        /// <summary>
        /// Processes the provided assembly.
        /// </summary>
        /// <param name="assembly">The assembly to process.</param>
        private static void ProcessAssembly(Assembly assembly)
        {
            string assemblyName = assembly.GetName().Name;

            if (Logger.IsVerbose3)
            {
                Logger.Verbose3("Processing assembly {0}", assemblyName);
            }
            // If the assembly is loaded for reflection only avoid processing it.
            if (assembly.ReflectionOnly)
            {
                return;
            }

            // Don't bother re-processing an assembly we've already scanned
            lock (ProcessedAssemblies)
            {
                if (!ProcessedAssemblies.Add(assembly))
                {
                    return;
                }
            }

            // If the assembly does not reference Orleans, avoid generating code for it.
            if (TypeUtils.IsOrleansOrReferencesOrleans(assembly))
            {
                // Code generation occurs in a self-contained assembly, so invoke it separately.
                CodeGeneratorManager.GenerateAndCacheCodeForAssembly(assembly);
            }

            // Process each type in the assembly.
            var shouldProcessSerialization = SerializationManager.ShouldFindSerializationInfo(assembly);
            var assemblyTypes = TypeUtils.GetDefinedTypes(assembly, Logger).ToArray();

            // Process each type in the assembly.
            List <Type> typesToFind = new List <Type>(assemblyTypes.Length);

            foreach (TypeInfo typeInfo in assemblyTypes)
            {
                try
                {
                    var    type     = typeInfo.AsType();
                    string typeName = typeInfo.FullName;
                    if (Logger.IsVerbose3)
                    {
                        Logger.Verbose3("Processing type {0}", typeName);
                    }
                    if (shouldProcessSerialization)
                    {
                        typesToFind.Add(type);
                    }

                    GrainFactory.FindSupportClasses(type);
                }
                catch (Exception exception)
                {
                    Logger.Error(ErrorCode.SerMgr_TypeRegistrationFailure, "Failed to load type " + typeInfo.FullName + " in assembly " + assembly.FullName + ".", exception);
                }
            }
            SerializationManager.FindSerializationInfo(typesToFind);
        }