static bool ValidateAssemblyCacheListIntegrity(HashSet <Assembly> assemblies, List <MefControlCacheAssemblyInfo> cachedAssemblyInfos, ICachingFaultInjector?cachingFaultInjector)
            {
                var currentAssemblies = new Dictionary <string, Guid> (assemblies.Count);

                foreach (var asm in assemblies)
                {
                    currentAssemblies.Add(asm.Location, asm.ManifestModule.ModuleVersionId);
                }

                foreach (var assemblyInfo in cachedAssemblyInfos)
                {
                    cachingFaultInjector?.FaultAssemblyInfo(assemblyInfo);

                    if (!currentAssemblies.TryGetValue(assemblyInfo.Location, out var mvid))
                    {
                        return(false);
                    }

                    if (mvid != assemblyInfo.ModuleVersionId)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            internal bool CanUse()
            {
                // If we don't have a control file, bail early
                if (!File.Exists(MefCacheControlFile) || !File.Exists(MefCacheFile))
                {
                    return(false);
                }

                using (var timer = Counters.CompositionCacheControl.BeginTiming()) {
                    // Read the cache from disk
                    var             serializer = new JsonSerializer();
                    MefControlCache controlCache;

                    try {
                        using (var sr = File.OpenText(MefCacheControlFile)) {
                            controlCache = (MefControlCache)serializer.Deserialize(sr, typeof(MefControlCache));
                        }
                    } catch (Exception ex) {
                        LoggingService.LogError("Could not deserialize MEF cache control", ex);
                        DeleteFiles();
                        return(false);
                    }

                    //this can return null (if the cache format changed?). clean up and start over.
                    if (controlCache == null)
                    {
                        LoggingService.LogError("MEF cache control deserialized as null");
                        DeleteFiles();
                        return(false);
                    }

                    var currentAssemblies = new HashSet <string> (Assemblies.Select(asm => asm.Location));

                    // Short-circuit on number of assemblies change
                    if (controlCache.AssemblyInfos.Length != currentAssemblies.Count)
                    {
                        return(false);
                    }

                    // Validate that the assemblies match and we have the same time stamps on them.
                    foreach (var assemblyInfo in controlCache.AssemblyInfos)
                    {
                        cachingFaultInjector?.FaultAssemblyInfo(assemblyInfo);
                        if (!currentAssemblies.Contains(assemblyInfo.Location))
                        {
                            return(false);
                        }

                        if (File.GetLastWriteTimeUtc(assemblyInfo.Location) != assemblyInfo.LastWriteTimeUtc)
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }