public AssemblyResolutionException(AssemblyNameReference reference, Exception innerException)
     : base(string.Format("Failed to resolve assembly: '{0}'", reference), innerException)
 {
     this.reference = reference;
 }
Example #2
0
        public static bool TryGetAssemblyNameReference(this ModuleDefinition module, AssemblyNameReference name_reference, out AssemblyNameReference assembly_reference)
        {
            var references = module.AssemblyReferences;

            for (int i = 0; i < references.Count; i++)
            {
                var reference = references [i];
                if (!Equals(name_reference, reference))
                {
                    continue;
                }

                assembly_reference = reference;
                return(true);
            }

            assembly_reference = null;
            return(false);
        }
 public AssemblyResolutionException(AssemblyNameReference reference)
     : this(reference, null)
 {
 }
        AssemblyDefinition GetCorlib(AssemblyNameReference reference, ReaderParameters parameters)
        {
            var version = reference.Version;
            var corlib  = typeof(object).Assembly.GetName();

            if (corlib.Version == version || IsZero(version))
            {
                return(GetAssembly(typeof(object).Module.FullyQualifiedName, parameters));
            }

            var path = Directory.GetParent(
                Directory.GetParent(
                    typeof(object).Module.FullyQualifiedName).FullName
                ).FullName;

            if (on_mono)
            {
                if (version.Major == 1)
                {
                    path = Path.Combine(path, "1.0");
                }
                else if (version.Major == 2)
                {
                    if (version.MajorRevision == 5)
                    {
                        path = Path.Combine(path, "2.1");
                    }
                    else
                    {
                        path = Path.Combine(path, "2.0");
                    }
                }
                else if (version.Major == 4)
                {
                    path = Path.Combine(path, "4.0");
                }
                else
                {
                    throw new NotSupportedException("Version not supported: " + version);
                }
            }
            else
            {
                switch (version.Major)
                {
                case 1:
                    if (version.MajorRevision == 3300)
                    {
                        path = Path.Combine(path, "v1.0.3705");
                    }
                    else
                    {
                        path = Path.Combine(path, "v1.1.4322");
                    }
                    break;

                case 2:
                    path = Path.Combine(path, "v2.0.50727");
                    break;

                case 4:
                    path = Path.Combine(path, "v4.0.30319");
                    break;

                default:
                    throw new NotSupportedException("Version not supported: " + version);
                }
            }

            var file = Path.Combine(path, "mscorlib.dll");

            if (File.Exists(file))
            {
                return(GetAssembly(file, parameters));
            }

            if (on_mono && Directory.Exists(path + "-api"))
            {
                file = Path.Combine(path + "-api", "mscorlib.dll");
                if (File.Exists(file))
                {
                    return(GetAssembly(file, parameters));
                }
            }

            return(null);
        }
 public AssemblyResolveEventArgs(AssemblyNameReference reference)
 {
     this.reference = reference;
 }
        public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
        {
            Mixin.CheckName(name);
            Mixin.CheckParameters(parameters);

            var assembly = SearchDirectory(name, directories, parameters);

            if (assembly != null)
            {
                return(assembly);
            }

            if (name.IsRetargetable)
            {
                // if the reference is retargetable, zero it
                name = new AssemblyNameReference(name.Name, Mixin.ZeroVersion)
                {
                    PublicKeyToken = Empty <byte> .Array,
                };
            }

#if NET_CORE
            assembly = SearchTrustedPlatformAssemblies(name, parameters);
            if (assembly != null)
            {
                return(assembly);
            }
#else
            var framework_dir  = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName);
            var framework_dirs = on_mono
                                ? new [] { framework_dir, Path.Combine(framework_dir, "Facades") }
                                : new [] { framework_dir };

            if (IsZero(name.Version))
            {
                assembly = SearchDirectory(name, framework_dirs, parameters);
                if (assembly != null)
                {
                    return(assembly);
                }
            }

            if (name.Name == "mscorlib")
            {
                assembly = GetCorlib(name, parameters);
                if (assembly != null)
                {
                    return(assembly);
                }
            }

            assembly = GetAssemblyInGac(name, parameters);
            if (assembly != null)
            {
                return(assembly);
            }

            assembly = SearchDirectory(name, framework_dirs, parameters);
            if (assembly != null)
            {
                return(assembly);
            }
#endif
            if (ResolveFailure != null)
            {
                assembly = ResolveFailure(this, name);
                if (assembly != null)
                {
                    return(assembly);
                }
            }

            throw new AssemblyResolutionException(name);
        }
 public virtual AssemblyDefinition Resolve(AssemblyNameReference name)
 {
     return(Resolve(name, new ReaderParameters()));
 }