+ if (resolvedTypeReferences == null)
+ resolvedTypeReferences = new HashSet<AssemblyDefinition> ();
+ if (resolvedTypeReferences.Contains (assembly))
+ return;
+ resolvedTypeReferences.Add (assembly);
+
+ var hash = new Dictionary<TypeReference,IMetadataScope> ();
+
+ foreach (TypeReference tr in assembly.MainModule.GetTypeReferences ()) {
+ if (hash.ContainsKey (tr))
+ continue;
+ var td = tr.Resolve ();
+ IMetadataScope scope = tr.Scope;
+ // at this stage reference might include things that can't be resolved
+ // and if it is (resolved) it needs to be kept only if marked (#16213)
+ if ((td != null) && Annotations.IsMarked (td))
+ scope = assembly.MainModule.Import (td).Scope;
+ hash.Add (tr, scope);
+ }
+
+ // Resolve everything first before updating scopes.
+ // If we set the scope to null, then calling Resolve() on any of its
+ // nested types would crash.
+
+ foreach (var e in hash) {
+ e.Key.Scope = e.Value;
+ }