public override ImmutableArray <PortableExecutableReference> ResolveReference(string reference, string baseFilePath, MetadataReferenceProperties properties) { // Implement cache to avoid more memory usage (https://github.com/dotnet/roslyn/issues/33304) var request = new ResolveReferenceRequest { reference = reference, baseFilePath = baseFilePath, properties = properties }; if (resolveReferenceCache.TryGetValue(request, out var resolvedReferences)) { return(resolvedReferences); } resolvedReferences = ResolveReferenceWithoutCache(request); resolveReferenceCache[request] = resolvedReferences; return(resolvedReferences); }
ImmutableArray <PortableExecutableReference> ResolveReferenceWithoutCache(ResolveReferenceRequest request) { lock (@lock) { // System.Console.WriteLine("ResolveReference: " + reference); var sha256Match = Regex.Match(request.reference, "sha256:([\\d\\w]+)", RegexOptions.IgnoreCase); if (sha256Match.Success) { var hash = Kalmit.CommonConversion.ByteArrayFromStringBase16(sha256Match.Groups[1].Value); var assembly = getFileFromHashSHA256?.Invoke(hash); if (assembly == null) { return(new ImmutableArray <PortableExecutableReference>()); } if (!Kalmit.CommonConversion.HashSHA256(assembly).SequenceEqual(hash)) { return(new ImmutableArray <PortableExecutableReference>()); } var assemblyMetadata = AssemblyMetadata.CreateFromImage(assembly); resolvedAssemblies = resolvedAssemblies.Add(assemblyMetadata); globalResolvedAssemblies.Add((assemblyMetadata, assembly)); return(ImmutableArray.Create(MetadataReference.CreateFromImage(assembly))); } } return (ScriptMetadataResolver.Default.ResolveReference( request.reference, request.baseFilePath, request.properties)); }