private AssemblyIdentity GetOrAddAssemblyIdentity(string fullPath) { Debug.Assert(PathUtilities.IsAbsolute(fullPath)); lock (_guard) { if (_loadedAssemblyIdentitiesByPath.TryGetValue(fullPath, out var existingIdentity)) { return(existingIdentity); } } AssemblyIdentity identity = AssemblyIdentityUtils.TryGetAssemblyIdentity(fullPath); return(AddToCache(fullPath, identity)); }
public Assembly Load(string displayName) { AssemblyIdentity requestedIdentity; if (!AssemblyIdentity.TryParseDisplayName(displayName, out requestedIdentity)) { return(null); } ImmutableArray <string> candidatePaths; lock (_guard) { Assembly existingAssembly; // First, check if this loader already loaded the requested assembly: if (_loadedAssembliesByIdentity.TryGetValue(requestedIdentity, out existingAssembly)) { return(existingAssembly); } // Second, check if an assembly file of the same simple name was registered with the loader: List <string> pathList; if (!_knownAssemblyPathsBySimpleName.TryGetValue(requestedIdentity.Name, out pathList)) { return(null); } Debug.Assert(pathList.Count > 0); candidatePaths = pathList.ToImmutableArray(); } // Multiple assemblies of the same simple name but different identities might have been registered. // Load the one that matches the requested identity (if any). foreach (var candidatePath in candidatePaths) { var candidateIdentity = AssemblyIdentityUtils.TryGetAssemblyIdentity(candidatePath); if (requestedIdentity.Equals(candidateIdentity)) { return(LoadFromPathUnchecked(candidatePath)); } } return(null); }