Ejemplo n.º 1
0
        private Assembly AssemblyResolve(object sender, IKVM.Reflection.ResolveEventArgs args)
        {
            AssemblyName name               = new AssemblyName(args.Name);
            AssemblyName previousMatch      = null;
            int          previousMatchLevel = 0;

            foreach (Assembly asm in universe.GetAssemblies())
            {
                if (Match(asm.GetName(), name, ref previousMatch, ref previousMatchLevel))
                {
                    return(asm);
                }
            }

            if (previousMatch != null)
            {
                //XXX: This is incorrect!
                return(universe.Load(previousMatch.FullName));
                //TODO: Rework this logic

                /*if (previousMatchLevel == 2)
                 * {
                 *  EmitWarning(WarningId.HigherVersion, "assuming assembly reference \"{0}\" matches \"{1}\", you may need to supply runtime policy.", previousMatch.FullName, name.FullName);
                 *  return universe.Load(previousMatch.FullName);
                 * }
                 * else if (args.RequestingAssembly != null)
                 * {
                 *  Console.Error.WriteLine("Error: Assembly '{0}' uses '{1}' which has a higher version than referenced assembly '{2}'", args.RequestingAssembly.FullName, name.FullName, previousMatch.FullName);
                 *  Environment.Exit(1);
                 *  return null;
                 * }
                 * else
                 * {
                 *  Console.Error.WriteLine("Error: Assembly '{0}' was requested which is a higher version than referenced assembly '{1}'", name.FullName, previousMatch.FullName);
                 *  if (args.RequestingAssembly != null)
                 *  {
                 *      Console.Error.WriteLine("Error: Request was made by the following assembly: '{0}'", args.RequestingAssembly.FullName);
                 *  }
                 *  Environment.Exit(1);
                 *  return null;
                 * }*/
            }
            else if (args.RequestingAssembly != null)
            {
                return(universe.CreateMissingAssembly(args.Name));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        private Assembly AssemblyResolve(object sender, IKVM.Reflection.ResolveEventArgs args)
        {
            AssemblyName name               = new AssemblyName(args.Name);
            AssemblyName previousMatch      = null;
            int          previousMatchLevel = 0;

            foreach (Assembly asm in universe.GetAssemblies())
            {
                if (Match(asm.GetName(), name, ref previousMatch, ref previousMatchLevel))
                {
                    return(asm);
                }
            }
            if (previousMatch != null)
            {
                if (previousMatchLevel == 2)
                {
#if NETFRAMEWORK
                    EmitWarning(WarningId.HigherVersion, "assuming assembly reference \"{0}\" matches \"{1}\", you may need to supply runtime policy", previousMatch.FullName, name.FullName);
#endif
                    return(universe.Load(previousMatch.FullName));
                }
                else if (args.RequestingAssembly != null)
                {
                    Console.Error.WriteLine("Error: Assembly '{0}' uses '{1}' which has a higher version than referenced assembly '{2}'", args.RequestingAssembly.FullName, name.FullName, previousMatch.FullName);
                    Environment.Exit(1);
                    return(null);
                }
                else
                {
                    Console.Error.WriteLine("Error: Assembly '{0}' was requested which is a higher version than referenced assembly '{1}'", name.FullName, previousMatch.FullName);
                    Environment.Exit(1);
                    return(null);
                }
            }
            else if (args.RequestingAssembly != null)
            {
                return(universe.CreateMissingAssembly(args.Name));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        Assembly AssemblyReferenceResolver(object sender, IKVM.Reflection.ResolveEventArgs args)
        {
            var refname = args.Name;

            if (refname == "mscorlib")
            {
                return(corlib);
            }

            Assembly version_mismatch = null;
            bool     is_fx_assembly   = false;

            foreach (var assembly in domain.GetAssemblies())
            {
                AssemblyComparisonResult result;
                if (!domain.CompareAssemblyIdentity(refname, false, assembly.FullName, false, out result))
                {
                    if ((result == AssemblyComparisonResult.NonEquivalentVersion || result == AssemblyComparisonResult.NonEquivalentPartialVersion) &&
                        (version_mismatch == null || version_mismatch.GetName().Version < assembly.GetName().Version) &&
                        !is_fx_assembly)
                    {
                        version_mismatch = assembly;
                    }

                    continue;
                }

                if (result == AssemblyComparisonResult.EquivalentFullMatch ||
                    result == AssemblyComparisonResult.EquivalentWeakNamed ||
                    result == AssemblyComparisonResult.EquivalentPartialMatch)
                {
                    return(assembly);
                }

                if (result == AssemblyComparisonResult.EquivalentFXUnified)
                {
                    is_fx_assembly = true;

                    if (version_mismatch == null || version_mismatch.GetName().Version < assembly.GetName().Version)
                    {
                        version_mismatch = assembly;
                    }

                    continue;
                }

                throw new NotImplementedException("Assembly equality = " + result.ToString());
            }

            if (version_mismatch != null)
            {
                if (version_mismatch is AssemblyBuilder)
                {
                    return(version_mismatch);
                }

                var v1 = new AssemblyName(refname).Version;
                var v2 = version_mismatch.GetName().Version;

                if (v1 > v2)
                {
                    if (resolved_version_mismatches == null)
                    {
                        resolved_version_mismatches = new Dictionary <AssemblyName, List <string[]> > ();
                    }

                    var             an = args.RequestingAssembly.GetName();
                    List <string[]> names;
                    if (!resolved_version_mismatches.TryGetValue(an, out names))
                    {
                        names = new List <string[]> ();
                        resolved_version_mismatches.Add(an, names);
                    }

                    names.Add(new[] {
                        args.RequestingAssembly.Location,
                        string.Format("Assembly `{0}' depends on `{1}' which has a higher version number than referenced assembly `{2}'",
                                      args.RequestingAssembly.FullName, refname, version_mismatch.GetName().FullName)
                    });

                    return(version_mismatch);
                }

                if (!is_fx_assembly)
                {
                    if (v1.Major != v2.Major || v1.Minor != v2.Minor)
                    {
                        compiler.Report.Warning(1701, 2,
                                                "Assuming assembly reference `{0}' matches assembly `{1}'. You may need to supply runtime policy",
                                                refname, version_mismatch.GetName().FullName);
                    }
                    else
                    {
                        compiler.Report.Warning(1702, 3,
                                                "Assuming assembly reference `{0}' matches assembly `{1}'. You may need to supply runtime policy",
                                                refname, version_mismatch.GetName().FullName);
                    }
                }

                return(version_mismatch);
            }

            //
            // Recursive reference to compiled assembly checks name only. Any other
            // details (PublicKey, Version, etc) are not yet known hence cannot be checked
            //
            ParsedAssemblyName referenced_assembly;

            if (Fusion.ParseAssemblyName(args.Name, out referenced_assembly) == ParseAssemblyResult.OK && CompiledAssembly.Name == referenced_assembly.Name)
            {
                return(CompiledAssembly.Builder);
            }

            // AssemblyReference has not been found in the domain
            // create missing reference and continue
            return(domain.CreateMissingAssembly(args.Name));
        }
Ejemplo n.º 4
0
Archivo: ikvm.cs Proyecto: nuxleus/mono
        Assembly AssemblyReferenceResolver(object sender, IKVM.Reflection.ResolveEventArgs args)
        {
            var refname = args.Name;

            if (refname == "mscorlib")
            {
                return(corlib);
            }

            Assembly version_mismatch = null;
            bool     is_fx_assembly   = false;

            foreach (var assembly in domain.GetAssemblies())
            {
                AssemblyComparisonResult result;
                if (!Fusion.CompareAssemblyIdentityPure(refname, false, assembly.FullName, false, out result))
                {
                    if ((result == AssemblyComparisonResult.NonEquivalentVersion || result == AssemblyComparisonResult.NonEquivalentPartialVersion) &&
                        (version_mismatch == null || version_mismatch.GetName().Version < assembly.GetName().Version) &&
                        !is_fx_assembly)
                    {
                        version_mismatch = assembly;
                    }

                    continue;
                }

                if (result == AssemblyComparisonResult.EquivalentFullMatch ||
                    result == AssemblyComparisonResult.EquivalentWeakNamed ||
                    result == AssemblyComparisonResult.EquivalentPartialMatch)
                {
                    return(assembly);
                }

                if (result == AssemblyComparisonResult.EquivalentFXUnified)
                {
                    is_fx_assembly = true;

                    if (version_mismatch == null || version_mismatch.GetName().Version < assembly.GetName().Version)
                    {
                        version_mismatch = assembly;
                    }

                    continue;
                }

                throw new NotImplementedException("Assembly equality = " + result.ToString());
            }

            if (version_mismatch != null)
            {
                if (version_mismatch is AssemblyBuilder)
                {
                    return(version_mismatch);
                }

                var v1 = new AssemblyName(refname).Version;
                var v2 = version_mismatch.GetName().Version;

                if (v1 > v2)
                {
//					compiler.Report.SymbolRelatedToPreviousError (args.RequestingAssembly.Location);
                    compiler.Report.Error(1705, "Assembly `{0}' references `{1}' which has a higher version number than imported assembly `{2}'",
                                          args.RequestingAssembly.FullName, refname, version_mismatch.GetName().FullName);

                    return(domain.CreateMissingAssembly(args.Name));
                }

                if (!is_fx_assembly)
                {
                    if (v1.Major != v2.Major || v1.Minor != v2.Minor)
                    {
                        compiler.Report.Warning(1701, 2,
                                                "Assuming assembly reference `{0}' matches assembly `{1}'. You may need to supply runtime policy",
                                                refname, version_mismatch.GetName().FullName);
                    }
                    else
                    {
                        compiler.Report.Warning(1702, 3,
                                                "Assuming assembly reference `{0}' matches assembly `{1}'. You may need to supply runtime policy",
                                                refname, version_mismatch.GetName().FullName);
                    }
                }

                return(version_mismatch);
            }

            // AssemblyReference has not been found in the domain
            // create missing reference and continue
            return(domain.CreateMissingAssembly(args.Name));
        }
Ejemplo n.º 5
0
        private Assembly AssemblyResolve(object sender, IKVM.Reflection.ResolveEventArgs args)
        {
            AssemblyName name               = new AssemblyName(args.Name);
            AssemblyName previousMatch      = null;
            int          previousMatchLevel = 0;

            foreach (Assembly asm in universe.GetAssemblies())
            {
                if (Match(asm.GetName(), name, ref previousMatch, ref previousMatchLevel))
                {
                    if (previousMatch?.FullName != null)
                    {
                        if (_repeatLoadCounter.ContainsKey(previousMatch.FullName))
                        {
                            _repeatLoadCounter.Remove(previousMatch.FullName);
                        }
                    }

                    return(asm);
                }
            }
            if (previousMatch != null)
            {
                if (previousMatchLevel == 2)
                {
                    EmitWarning(WarningId.HigherVersion, "assuming assembly reference \"{0}\" matches \"{1}\", you may need to supply runtime policy", previousMatch.FullName, name.FullName);
                    if (_repeatLoadCounter.ContainsKey(previousMatch.FullName))
                    {
                        _repeatLoadCounter[previousMatch.FullName]++;
                    }
                    else
                    {
                        _repeatLoadCounter.Add(previousMatch.FullName, 1);
                    }

                    if (_repeatLoadCounter[previousMatch.FullName] > 100)
                    {
                        throw new Exception("Excessive repeating load attempt detected");
                    }

                    return(universe.Load(previousMatch.FullName));
                }
                else if (args.RequestingAssembly != null)
                {
                    Console.Error.WriteLine("Error: Assembly '{0}' uses '{1}' which has a higher version than referenced assembly '{2}'", args.RequestingAssembly.FullName, name.FullName, previousMatch.FullName);
                    Environment.Exit(1);
                    return(null);
                }
                else
                {
                    Console.Error.WriteLine("Error: Assembly '{0}' was requested which is a higher version than referenced assembly '{1}'", name.FullName, previousMatch.FullName);
                    Environment.Exit(1);
                    return(null);
                }
            }
            else if (args.RequestingAssembly != null)
            {
                return(universe.CreateMissingAssembly(args.Name));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        private AssemblyName ReadCustomAttributesFromTemplateFile(string templateFile, AssemblyName aname)
        {
            // LAMESPEC: according to MSDN, the template assembly must have a
            // strong name but this is not enforced
            var asm = universe.LoadFile(templateFile);

            // Create missing assemblies, we don't want to load them!
            // Code taken from ikdasm
            var names = new HashSet <string> ();

            AssemblyName[] assembly_refs = asm.ManifestModule.__GetReferencedAssemblies();

            var resolved_assemblies = new Assembly [assembly_refs.Length];

            for (int i = 0; i < resolved_assemblies.Length; i++)
            {
                string name = assembly_refs [i].Name;

                while (names.Contains(name))
                {
                    name = name + "_" + i;
                }
                names.Add(name);
                resolved_assemblies [i] = universe.CreateMissingAssembly(assembly_refs [i].FullName);
            }
            asm.ManifestModule.__ResolveReferencedAssemblies(resolved_assemblies);

            foreach (var attr_data in asm.__GetCustomAttributes(null, false))
            {
                string asm_name = attr_data.AttributeType.Assembly.GetName().Name;
                if (asm_name != "mscorlib")
                {
                    continue;
                }

                switch (attr_data.AttributeType.FullName)
                {
                case "System.Reflection.AssemblyKeyFileAttribute": {
                    if (keyfile != null)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // / AssemblyKeyFileAttribute .ctor(string keyFile)
                    string key_file_value = (string)attr_data.ConstructorArguments [0].Value;

                    if (!String.IsNullOrEmpty(key_file_value))
                    {
                        keyfile = Path.Combine(Path.GetDirectoryName(templateFile), key_file_value);
                    }
                }
                break;

                case "System.Reflection.AssemblyDelaySignAttribute": {
                    if (delaysign != DelaySign.NotSet)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // AssemblyDelaySignAttribute .ctor(bool delaySign)
                    bool delay_sign_value = (bool)attr_data.ConstructorArguments [0].Value;
                    delaysign = delay_sign_value ? DelaySign.Yes : DelaySign.No;
                }
                break;

                case "System.Reflection.AssemblyKeyNameAttribute": {
                    if (keyname != null)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // AssemblyKeyNameAttribute .ctor(string keyName)
                    string key_name_value = (string)attr_data.ConstructorArguments [0].Value;

                    // ignore null or zero-length keyname
                    if (!String.IsNullOrEmpty(key_name_value))
                    {
                        keyname = key_name_value;
                    }
                }
                break;

                case "System.Reflection.AssemblyTitleAttribute": {
                    if (title != null)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // AssemblyTitleAttribute .ctor(string title)
                    string title_value = (string)attr_data.ConstructorArguments [0].Value;

                    if (!String.IsNullOrEmpty(title_value))
                    {
                        title = title_value;
                    }
                }
                break;

                case "System.Reflection.AssemblyDescriptionAttribute": {
                    if (description != null)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // AssemblyDescriptionAttribute .ctor(string description)
                    string description_value = (string)attr_data.ConstructorArguments [0].Value;

                    if (!String.IsNullOrEmpty(description_value))
                    {
                        description = description_value;
                    }
                }
                break;

                case "System.Reflection.AssemblyProductAttribute": {
                    if (product != null)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // AssemblyProductAttribute .ctor(string product)
                    string product_value = (string)attr_data.ConstructorArguments [0].Value;

                    if (!String.IsNullOrEmpty(product_value))
                    {
                        product = product_value;
                    }
                }
                break;

                case "System.Reflection.AssemblyCompanyAttribute": {
                    if (company != null)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // AssemblyCompanyAttribute .ctor(string company)
                    string company_value = (string)attr_data.ConstructorArguments [0].Value;

                    if (!String.IsNullOrEmpty(company_value))
                    {
                        company = company_value;
                    }
                }
                break;

                case "System.Reflection.AssemblyCopyrightAttribute": {
                    if (copyright != null)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // AssemblyCopyrightAttribute .ctor(string copyright)
                    string copyright_value = (string)attr_data.ConstructorArguments [0].Value;

                    if (!String.IsNullOrEmpty(copyright_value))
                    {
                        copyright = copyright_value;
                    }
                }
                break;

                case "System.Reflection.AssemblyTrademarkAttribute": {
                    if (trademark != null)
                    {
                        // ignore if specified on command line
                        continue;
                    }

                    // AssemblyTrademarkAttribute .ctor(string trademark)
                    string trademark_value = (string)attr_data.ConstructorArguments [0].Value;

                    if (!String.IsNullOrEmpty(trademark_value))
                    {
                        trademark = trademark_value;
                    }
                }
                break;
                }
            }

            var asm_name_for_template_file = asm.GetName();

            aname.Version       = asm_name_for_template_file.Version;
            aname.HashAlgorithm = asm_name_for_template_file.HashAlgorithm;

            return(aname);
        }
Ejemplo n.º 7
0
        private Assembly universe_AssemblyResolve(object sender, IKVM.Reflection.ResolveEventArgs args)
        {
            AssemblyName name               = new AssemblyName(args.Name);
            AssemblyName previousMatch      = null;
            int          previousMatchLevel = 0;

            foreach (Assembly asm in universe.GetAssemblies())
            {
                if (Match(asm.GetName(), name, ref previousMatch, ref previousMatchLevel))
                {
                    return(asm);
                }
            }
            foreach (string file in FindAssemblyPath(name.Name + ".dll"))
            {
                if (Match(AssemblyName.GetAssemblyName(file), name, ref previousMatch, ref previousMatchLevel))
                {
                    return(LoadFile(file));
                }
            }
            if (args.RequestingAssembly != null)
            {
                string path = Path.Combine(Path.GetDirectoryName(args.RequestingAssembly.Location), name.Name + ".dll");
                if (File.Exists(path) && Match(AssemblyName.GetAssemblyName(path), name, ref previousMatch, ref previousMatchLevel))
                {
                    return(LoadFile(path));
                }
            }
            string hintpath;

            if (hintpaths.TryGetValue(name.FullName, out hintpath))
            {
                string path = Path.Combine(hintpath, name.Name + ".dll");
                if (File.Exists(path) && Match(AssemblyName.GetAssemblyName(path), name, ref previousMatch, ref previousMatchLevel))
                {
                    return(LoadFile(path));
                }
            }
            if (previousMatch != null)
            {
                if (previousMatchLevel == 2)
                {
                    EmitWarning(WarningId.HigherVersion, "assuming assembly reference \"{0}\" matches \"{1}\", you may need to supply runtime policy", previousMatch.FullName, name.FullName);
                    return(LoadFile(new Uri(previousMatch.CodeBase).LocalPath));
                }
                else if (args.RequestingAssembly != null)
                {
                    Console.Error.WriteLine("Error: Assembly '{0}' uses '{1}' which has a higher version than referenced assembly '{2}'", args.RequestingAssembly.FullName, name.FullName, previousMatch.FullName);
                }
                else
                {
                    Console.Error.WriteLine("Error: Assembly '{0}' was requested which is a higher version than referenced assembly '{1}'", name.FullName, previousMatch.FullName);
                }
            }
            else
            {
#if STUB_GENERATOR
                return(universe.CreateMissingAssembly(args.Name));
#else
                Console.Error.WriteLine("Error: unable to find assembly '{0}'", args.Name);
                if (args.RequestingAssembly != null)
                {
                    Console.Error.WriteLine("    (a dependency of '{0}')", args.RequestingAssembly.FullName);
                }
#endif
            }
            Environment.Exit(1);
            return(null);
        }