/// <summary> /// Returns the original location of the corresponding assembly if available, otherwise returns the /// location of the shadow copy. If the corresponding assembly is not in the GAC, null is returned. /// </summary> public static string GetLocation(AssemblyReference assemblyReference) { if(assemblyReference == null) { Debug.Fail("assemblyReference == null"); return null; } lock(GlobalAssemblyCache.Lock) { if(!GlobalAssemblyCache.FusionLoaded) { GlobalAssemblyCache.FusionLoaded = true; System.Reflection.Assembly systemAssembly = typeof(object).Assembly; //^ assume systemAssembly != null && systemAssembly.Location != null; string dir = Path.GetDirectoryName(systemAssembly.Location); //^ assume dir != null; GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll")); } IAssemblyEnum assemblyEnum; CreateAssemblyEnum(out assemblyEnum, null, null, GAC, 0); if(assemblyEnum == null) return null; IApplicationContext applicationContext; IAssemblyName currentName; while(assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0) { //^ assume currentName != null; AssemblyName aName = new AssemblyName(currentName); if(assemblyReference.Matches(aName.Name, aName.Version, aName.Culture, aName.PublicKeyToken)) { string codeBase = aName.CodeBase; if(codeBase != null && codeBase.StartsWith("file:///")) return codeBase.Substring(8); return aName.GetLocation(); } } return null; } }
public virtual bool MayAccessInternalTypesOf(AssemblyNode assembly) { if(this == assembly) return true; if(assembly == null || SystemTypes.InternalsVisibleToAttribute == null) return false; if(this.friends == null) this.friends = new TrivialHashtable(); object ob = this.friends[assembly.UniqueKey]; if(ob == (object)string.Empty) return false; if(ob == this) return true; AttributeList attributes = assembly.Attributes; for(int i = 0, n = attributes == null ? 0 : attributes.Count; i < n; i++) { //^ assert attributes != null; AttributeNode attr = attributes[i]; if(attr == null) continue; MemberBinding mb = attr.Constructor as MemberBinding; if(mb != null) { if(mb.BoundMember == null) continue; if(mb.BoundMember.DeclaringType != SystemTypes.InternalsVisibleToAttribute) continue; } else { Literal lit = attr.Constructor as Literal; if(lit == null) continue; if((lit.Value as TypeNode) != SystemTypes.InternalsVisibleToAttribute) continue; } if(attr.Expressions == null || attr.Expressions.Count < 1) continue; Literal argLit = attr.Expressions[0] as Literal; if(argLit == null) continue; string friendName = argLit.Value as string; if(friendName == null) continue; try { AssemblyReference ar = new AssemblyReference(friendName); byte[] tok = ar.PublicKeyToken; if(tok != null && this.PublicKeyOrToken != null) tok = this.PublicKeyToken; if(!ar.Matches(this.Name, ar.Version, ar.Culture, tok)) continue; } catch(ArgumentException e) { if(this.MetadataImportErrors == null) this.MetadataImportErrors = new ArrayList(); this.MetadataImportErrors.Add(e.Message); continue; } this.friends[assembly.UniqueKey] = this; return true; } this.friends[assembly.UniqueKey] = string.Empty; return false; }