Пример #1
0
        public void VerifyProcessorArchitectureDoesNotCrashFullFusionNameSpecificVersion()
        {
            AssemblyNameExtension fusionName = new AssemblyNameExtension("System, PublicKeyToken=b77a5c561934e089, ProcessorArchitecture=MSIL");
            string path = GlobalAssemblyCache.GetLocation(fusionName, SystemProcessorArchitecture.MSIL, getRuntimeVersion, new Version("2.0.50727"), true, new FileExists(MockFileExists), _getPathFromFusionName, null /* use the real gac enumerator*/, true);

            Assert.Null(path);
        }
Пример #2
0
        public void VerifyNullPublicKeyspecificVersion()
        {
            AssemblyNameExtension fusionName = new AssemblyNameExtension("System, PublicKeyToken=null");
            string path = GlobalAssemblyCache.GetLocation(fusionName, SystemProcessorArchitecture.None, getRuntimeVersion, new Version("2.0.50727"), false, new FileExists(MockFileExists), _getPathFromFusionName, _gacEnumerator, true);

            Assert.Null(path);
        }
Пример #3
0
 public void VerifyEmptyPublicKeyspecificVersion()
 {
     Assert.Throws <FileLoadException>(() =>
     {
         AssemblyNameExtension fusionName = new AssemblyNameExtension("System, PublicKeyToken=");
         string path = GlobalAssemblyCache.GetLocation(fusionName, ProcessorArchitecture.None, getRuntimeVersion, new Version("2.0.50727"), false, new FileExists(MockFileExists), _getPathFromFusionName, _gacEnumerator, true);
     }
                                       );
 }
Пример #4
0
        public void VerifyFusionNamev2057020SpecificVersion()
        {
            // We want to pass a very generic name to get the correct gac entries.
            AssemblyNameExtension fusionName = new AssemblyNameExtension("System, Version=2.0.0.0");


            string path = GlobalAssemblyCache.GetLocation(fusionName, SystemProcessorArchitecture.None, _runtimeVersion, new Version("2.0.0"), false, new FileExists(MockFileExists), _getPathFromFusionName, _gacEnumerator, true);

            Assert.NotNull(path);
            Assert.Equal(system2Path, path);
        }
Пример #5
0
        public void VerifySimpleNamev2057020()
        {
            // We want to pass a very generic name to get the correct gac entries.
            AssemblyNameExtension fusionName = new AssemblyNameExtension("System");


            string path = GlobalAssemblyCache.GetLocation(fusionName, SystemProcessorArchitecture.None, _runtimeVersion, new Version("2.0.57027"), false, new FileExists(MockFileExists), _getPathFromFusionName, _gacEnumerator, false);

            Assert.NotNull(path);
            Assert.True(path.Equals(system2Path, StringComparison.OrdinalIgnoreCase));
        }
Пример #6
0
        /// <summary>
        /// This is used to try and resolve an assembly reference
        /// </summary>
        /// <param name="reference">The assembly reference</param>
        /// <param name="referrer">The module requiring the reference</param>
        /// <returns>The assembly node if resolved or null if not resolved</returns>
        public virtual AssemblyNode ResolveReference(AssemblyReference reference, Module referrer)
        {
            AssemblyNode assembly;

            if (reference == null)
            {
                throw new ArgumentNullException("reference");
            }

            // Try to get it from the cache
            string name = reference.StrongName;

            if (cache.ContainsKey(name))
            {
                return(cache[name]);
            }

            // Try to get it from the GAC if so indicated
            if (this.UseGac)
            {
                string location = GlobalAssemblyCache.GetLocation(reference);

                if (location != null)
                {
                    assembly = AssemblyNode.GetAssembly(location, null, false, false, false, false);

                    if (assembly != null)
                    {
                        this.Add(assembly);
                        return(assembly);
                    }
                }
            }

            // Try the redirects if not found
            foreach (BindingRedirectSettings brs in redirects)
            {
                if (brs.IsRedirectFor(name) && cache.ContainsKey(brs.StrongName))
                {
                    ConsoleApplication.WriteMessage(LogLevel.Info, "Using redirect '{0}' in place of '{1}'",
                                                    brs.StrongName, name);

                    assembly = cache[brs.StrongName];

                    // Add the same assembly under the current name
                    cache.Add(name, assembly);
                    return(assembly);
                }
            }

            // Couldn't find it; return null
            return(null);
        }
Пример #7
0
        public virtual AssemblyNode ResolveReference(AssemblyReference reference, Module module)
        {
            if (reference == null)
            {
                throw new ArgumentNullException("reference");
            }

            //Console.WriteLine("resolving {0}", reference.StrongName);

            // try to get it from the cache
            string name = reference.StrongName;

            if (cache.ContainsKey(name))
            {
                return(cache[name]);
            }

            // try to get it from the gac
            if (useGac)
            {
                string location = GlobalAssemblyCache.GetLocation(reference);
                if (location != null)
                {
                    AssemblyNode assembly = AssemblyNode.GetAssembly(location, null, false, false, false, false);
                    if (assembly != null)
                    {
                        Add(assembly);
                        return(assembly);
                    }
                }
            }

            // couldn't find it; return null
            // Console.WriteLine("returning null on request for {0}", reference.StrongName);
            //OnUnresolvedAssemblyReference(reference, module);
            return(null);
        }
Пример #8
0
        /// <summary>
        /// This is used to try and resolve an assembly reference
        /// </summary>
        /// <param name="reference">The assembly reference</param>
        /// <param name="referrer">The module requiring the reference</param>
        /// <returns>The assembly node if resolved or null if not resolved</returns>
        public virtual AssemblyNode ResolveReference(AssemblyReference reference, Module referrer)
        {
            AssemblyNode assembly;

            if (reference == null)
            {
                throw new ArgumentNullException("reference");
            }

            // Try to get it from the cache
            string name = reference.StrongName;

            if (cache.ContainsKey(name))
            {
                return(cache[name]);
            }

            // Try to get it from the GAC if so indicated
            if (this.UseGac)
            {
                string location = GlobalAssemblyCache.GetLocation(reference);

                if (location != null)
                {
                    assembly = AssemblyNode.GetAssembly(location, null, false, false, false, false);

                    if (assembly != null)
                    {
                        this.Add(assembly);
                        return(assembly);
                    }
                }
            }

            // Try the redirects if not found
            foreach (BindingRedirectSettings brs in redirects)
            {
                if (brs.IsRedirectFor(name) && cache.ContainsKey(brs.StrongName))
                {
                    ConsoleApplication.WriteMessage(LogLevel.Info, "Using redirect '{0}' in place of '{1}'",
                                                    brs.StrongName, name);

                    assembly = cache[brs.StrongName];

                    // Add the same assembly under the current name
                    cache.Add(name, assembly);
                    return(assembly);
                }
            }

            // For mscorlib v255.255.255.255, redirect to System.Runtime.  This is typically one like a .NETCore
            // framework which redirects all of the system types there.
            if (reference.Name == "mscorlib" && reference.Version.Major == 255)
            {
                // The system assembly should be set.  If so, it'll point to the one we need.
                if (SystemTypes.SystemAssembly != null)
                {
                    assembly = SystemTypes.SystemAssembly;
                    cache.Add(name, assembly);
                    return(assembly);
                }

                // If not, look for it in the cache
                string key = cache.Keys.FirstOrDefault(k => k.StartsWith("System.Runtime,", StringComparison.Ordinal));

                if (key != null)
                {
                    assembly = cache[key];
                    cache.Add(name, assembly);
                    return(assembly);
                }
            }

            if (reference.Name != "mscorlib")
            {
                // Try for a framework assembly in the target platform
                var assemblyRef = (AssemblyReference)TargetPlatform.AssemblyReferenceFor[Identifier.For(reference.Name).UniqueIdKey];

                if (assemblyRef != null && System.IO.File.Exists(assemblyRef.Location))
                {
                    assembly = AssemblyNode.GetAssembly(assemblyRef.Location, null, false, false, false, false);

                    ConsoleApplication.WriteMessage(LogLevel.Info, "Using framework redirect '{0}' in place of '{1}'",
                                                    assembly.StrongName, name);

                    cache.Add(name, assembly);
                    return(assembly);
                }
            }

            // Couldn't find it; return null
            return(null);
        }