示例#1
0
        private bool Match(AssemblyName assemblyDef, AssemblyName assemblyRef, ref AssemblyName bestMatch, ref int bestMatchLevel)
        {
            // Match levels:
            //   0 = no match
            //   1 = lower version match (i.e. not a suitable match, but used in error reporting: something was found but the version was too low)
            //   2 = higher version potential match (i.e. we can use this version, but if it is available the exact match will be preferred)
            //
            // If we find a perfect match, bestMatch is not changed but we return true to signal that the search can end right now.
            AssemblyComparisonResult result;

            universe.CompareAssemblyIdentity(assemblyRef.FullName, false, assemblyDef.FullName, true, out result);
            switch (result)
            {
            case AssemblyComparisonResult.EquivalentFullMatch:
            case AssemblyComparisonResult.EquivalentPartialMatch:
            case AssemblyComparisonResult.EquivalentFXUnified:
            case AssemblyComparisonResult.EquivalentPartialFXUnified:
            case AssemblyComparisonResult.EquivalentPartialWeakNamed:
            case AssemblyComparisonResult.EquivalentWeakNamed:
                return(true);

            case AssemblyComparisonResult.NonEquivalentPartialVersion:
            case AssemblyComparisonResult.NonEquivalentVersion:
                if (bestMatchLevel < 1)
                {
                    bestMatchLevel = 1;
                    bestMatch      = assemblyDef;
                }
                return(true);

            case AssemblyComparisonResult.EquivalentUnified:
            case AssemblyComparisonResult.EquivalentPartialUnified:
                // Hack: System.Runtime.Extensions
                if (bestMatchLevel < 2)
                {
                    bestMatchLevel = 2;
                    bestMatch      = assemblyDef;
                }
                return(true);

            case AssemblyComparisonResult.NonEquivalent:
            case AssemblyComparisonResult.Unknown:
                return(false);

            default:
                throw new NotImplementedException();
            }
        }
示例#2
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));
        }
示例#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)
                {
//					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));
        }