public sealed override IList <AssemblyBindResult> GetLoadedAssemblies()
        {
            List <AssemblyBindResult> loadedAssemblies = new List <AssemblyBindResult>(ScopeGroups.Length);

            foreach (KeyValuePair <RuntimeAssemblyName, ScopeDefinitionGroup> group in ScopeGroups)
            {
                ScopeDefinitionGroup scopeDefinitionGroup = group.Value;

                AssemblyBindResult result = default(AssemblyBindResult);
                result.Reader = scopeDefinitionGroup.CanonicalScope.Reader;
                result.ScopeDefinitionHandle = scopeDefinitionGroup.CanonicalScope.Handle;
                result.OverflowScopes        = scopeDefinitionGroup.OverflowScopes;
                loadedAssemblies.Add(result);
            }

            InsertEcmaLoadedAssemblies(loadedAssemblies);

            return(loadedAssemblies);
        }
        public sealed override bool Bind(RuntimeAssemblyName refName, bool cacheMissedLookups, out AssemblyBindResult result, out Exception exception)
        {
            bool foundMatch = false;

            result    = default(AssemblyBindResult);
            exception = null;

            Exception preferredException = null;

            foreach (KeyValuePair <RuntimeAssemblyName, ScopeDefinitionGroup> group in ScopeGroups)
            {
                if (AssemblyNameMatches(refName, group.Key, ref preferredException))
                {
                    if (foundMatch)
                    {
                        exception = new AmbiguousMatchException();
                        return(false);
                    }

                    foundMatch = true;
                    ScopeDefinitionGroup scopeDefinitionGroup = group.Value;

                    result.Reader = scopeDefinitionGroup.CanonicalScope.Reader;
                    result.ScopeDefinitionHandle = scopeDefinitionGroup.CanonicalScope.Handle;
                    result.OverflowScopes        = scopeDefinitionGroup.OverflowScopes;
                }
            }

            BindEcmaAssemblyName(refName, cacheMissedLookups, ref result, ref exception, ref preferredException, ref foundMatch);
            if (exception != null)
            {
                return(false);
            }

            if (!foundMatch)
            {
                exception = preferredException ?? new FileNotFoundException(SR.Format(SR.FileNotFound_AssemblyNotFound, refName.FullName));
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        private void AddScopesFromReaderToGroups(LowLevelDictionaryWithIEnumerable <AssemblyNameKey, ScopeDefinitionGroup> groups, MetadataReader reader)
        {
            foreach (ScopeDefinitionHandle scopeDefinitionHandle in reader.ScopeDefinitions)
            {
                AssemblyName    defName     = this.CreateAssemblyNameFromMetadata(reader, scopeDefinitionHandle);
                string          defFullName = defName.FullName;
                AssemblyNameKey nameKey     = new AssemblyNameKey(defFullName, defName);

                ScopeDefinitionGroup scopeDefinitionGroup;
                if (groups.TryGetValue(nameKey, out scopeDefinitionGroup))
                {
                    scopeDefinitionGroup.AddOverflowScope(new QScopeDefinition(reader, scopeDefinitionHandle));
                }
                else
                {
                    scopeDefinitionGroup = new ScopeDefinitionGroup(new QScopeDefinition(reader, scopeDefinitionHandle));
                    groups.Add(nameKey, scopeDefinitionGroup);
                }
            }
        }
Beispiel #4
0
        public sealed override bool Bind(AssemblyName refName, out MetadataReader reader, out ScopeDefinitionHandle scopeDefinitionHandle, out IEnumerable <QScopeDefinition> overflowScopes, out Exception exception)
        {
            bool foundMatch = false;

            reader = null;
            scopeDefinitionHandle = default(ScopeDefinitionHandle);
            exception             = null;
            overflowScopes        = null;

            foreach (KeyValuePair <string, ScopeDefinitionGroup> group in ScopeGroups)
            {
                AssemblyName defName = new AssemblyName(group.Key);
                if (AssemblyNameMatches(refName, defName))
                {
                    if (foundMatch)
                    {
                        exception = new AmbiguousMatchException();
                        return(false);
                    }

                    foundMatch = true;
                    ScopeDefinitionGroup scopeDefinitionGroup = group.Value;

                    reader = scopeDefinitionGroup.CanonicalScope.Reader;
                    scopeDefinitionHandle = scopeDefinitionGroup.CanonicalScope.Handle;
                    overflowScopes        = scopeDefinitionGroup.OverflowScopes;
                }
            }

            if (!foundMatch)
            {
                exception = new IOException(SR.Format(SR.FileNotFound_AssemblyNotFound, refName.FullName));
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public sealed override bool Bind(RuntimeAssemblyName refName, out AssemblyBindResult result, out Exception exception)
        {
            bool foundMatch = false;

            result    = default(AssemblyBindResult);
            exception = null;

            refName = refName.CanonicalizePublicKeyToken();

            // At least one real-world app calls Type.GetType() for "char" using the assembly name "mscorlib". To accomodate this,
            // we will adopt the desktop CLR rule that anything named "mscorlib" automatically binds to the core assembly.
            bool useMscorlibNameCompareFunc    = false;
            RuntimeAssemblyName compareRefName = refName;

            if (refName.Name == "mscorlib")
            {
                useMscorlibNameCompareFunc = true;
                compareRefName             = AssemblyNameParser.Parse(AssemblyBinder.DefaultAssemblyNameForGetType);
            }

            foreach (KeyValuePair <RuntimeAssemblyName, ScopeDefinitionGroup> group in ScopeGroups)
            {
                bool nameMatches;
                if (useMscorlibNameCompareFunc)
                {
                    nameMatches = MscorlibAssemblyNameMatches(compareRefName, group.Key);
                }
                else
                {
                    nameMatches = AssemblyNameMatches(refName, group.Key);
                }

                if (nameMatches)
                {
                    if (foundMatch)
                    {
                        exception = new AmbiguousMatchException();
                        return(false);
                    }

                    foundMatch = true;
                    ScopeDefinitionGroup scopeDefinitionGroup = group.Value;

                    result.Reader = scopeDefinitionGroup.CanonicalScope.Reader;
                    result.ScopeDefinitionHandle = scopeDefinitionGroup.CanonicalScope.Handle;
                    result.OverflowScopes        = scopeDefinitionGroup.OverflowScopes;
                }
            }

            BindEcmaAssemblyName(refName, ref result, ref exception, ref foundMatch);
            if (exception != null)
            {
                return(false);
            }

            if (!foundMatch)
            {
                exception = new IOException(SR.Format(SR.FileNotFound_AssemblyNotFound, refName.FullName));
                return(false);
            }

            return(true);
        }
        private void AddScopesFromReaderToGroups(LowLevelDictionaryWithIEnumerable<string, ScopeDefinitionGroup> groups, MetadataReader reader)
        {
            foreach (ScopeDefinitionHandle scopeDefinitionHandle in reader.ScopeDefinitions)
            {
                AssemblyName defName = this.CreateAssemblyNameFromMetadata(reader, scopeDefinitionHandle);
                string defFullName = defName.FullName;

                ScopeDefinitionGroup scopeDefinitionGroup;
                if (groups.TryGetValue(defFullName, out scopeDefinitionGroup))
                {
                    scopeDefinitionGroup.AddOverflowScope(new QScopeDefinition(reader, scopeDefinitionHandle));
                }
                else
                {
                    scopeDefinitionGroup = new ScopeDefinitionGroup(new QScopeDefinition(reader, scopeDefinitionHandle));
                    groups.Add(defFullName, scopeDefinitionGroup);
                }
            }
        }