Ejemplo n.º 1
0
        public static bool IsFrameworkAssembly(this AssemblyIdentity identity)
        {
            string token = identity.GetPublicKeyToken();

            string mapped = MapPublicKeyTokenToName(token);

            // If the token is the same then we don't a name for it and thus we don't know about it.
            return(token != mapped);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method that loads assemblies given a list of identities
        /// </summary>
        /// <param name="identities">Collection of identities to load</param>
        /// <param name="logErrorOrWarningCallback">Callback method that takes a message(string), an error level(ErrorTreatment), and a flag for isVersionMismatch(bool)</param>
        /// <returns>Collection of Assemblies</returns>
        public IEnumerable <IAssembly> LoadAssemblies(IEnumerable <AssemblyIdentity> identities, bool warnOnVersionMismatch, Action <string, ErrorTreatment> logErrorOrWarningCallback)
        {
            List <IAssembly> matchingAssemblies = new List <IAssembly>();

            foreach (var unmappedIdentity in identities)
            {
                // Remap the name and clear the location.
                AssemblyIdentity identity = new AssemblyIdentity(this.NameTable.GetNameFor(unmappedIdentity.Name.Value),
                                                                 unmappedIdentity.Culture, unmappedIdentity.Version, unmappedIdentity.PublicKeyToken, "");

                AssemblyIdentity matchingIdentity = this.ProbeLibPaths(identity);

                var matchingAssembly = this.LoadAssembly(matchingIdentity);
                if ((matchingAssembly == null || matchingAssembly == Dummy.Assembly) && logErrorOrWarningCallback != null)
                {
                    string message = string.Format("Failed to find or load matching assembly '{0}'.", identity.Name.Value);
                    logErrorOrWarningCallback(message, LoadErrorTreatment);
                    continue;
                }

                if (!identity.Version.Equals(matchingAssembly.Version) && logErrorOrWarningCallback != null && warnOnVersionMismatch)
                {
                    string message = string.Format("Found '{0}' with version '{1}' instead of '{2}'.", identity.Name.Value, matchingAssembly.Version, identity.Version);
                    logErrorOrWarningCallback(message, ErrorTreatment.TreatAsWarning);
                }

                string idPKT       = identity.GetPublicKeyToken();
                string matchingPKT = matchingAssembly.GetPublicKeyToken();

                if (!idPKT.Equals(matchingPKT) && logErrorOrWarningCallback != null)
                {
                    string message = string.Format("Found '{0}' with PublicKeyToken '{1}' instead of '{2}'.", identity.Name.Value, matchingPKT, idPKT);
                    logErrorOrWarningCallback(message, ErrorTreatment.TreatAsWarning);
                }

                matchingAssemblies.Add(matchingAssembly);
            }

            return(matchingAssemblies);
        }
Ejemplo n.º 3
0
        public IEnumerable <IAssembly> LoadAssemblies(IEnumerable <AssemblyIdentity> identities, bool warnOnVersionMismatch)
        {
            List <IAssembly> matchingAssemblies = new List <IAssembly>();

            foreach (var unmappedIdentity in identities)
            {
                // Remap the name and clear the location.
                AssemblyIdentity identity = new AssemblyIdentity(this.NameTable.GetNameFor(unmappedIdentity.Name.Value),
                                                                 unmappedIdentity.Culture, unmappedIdentity.Version, unmappedIdentity.PublicKeyToken, "");

                AssemblyIdentity matchingIdentity = this.ProbeLibPaths(identity);

                var matchingAssembly = this.LoadAssembly(matchingIdentity);
                if (matchingAssembly == null || matchingAssembly == Dummy.Assembly)
                {
                    TraceLoadError("Failed to find or load matching assembly '{0}'.", identity.Name.Value);
                    continue;
                }

                if (warnOnVersionMismatch && !identity.Version.Equals(matchingAssembly.Version))
                {
                    Trace.TraceWarning("Found '{0}' with version '{1}' instead of '{2}'.",
                                       identity.Name.Value, matchingAssembly.Version, identity.Version);
                }

                string idPKT       = identity.GetPublicKeyToken();
                string matchingPKT = matchingAssembly.GetPublicKeyToken();

                if (!idPKT.Equals(matchingPKT))
                {
                    Trace.TraceWarning("Found '{0}' with PublicKeyToken '{1}' instead of '{2}'.",
                                       identity.Name.Value, matchingPKT, idPKT);
                }

                matchingAssemblies.Add(matchingAssembly);
            }

            return(matchingAssemblies);
        }
Ejemplo n.º 4
0
 public static string GetPublicKeyTokenName(this AssemblyIdentity identity)
 {
     return(MapPublicKeyTokenToName(identity.GetPublicKeyToken()));
 }