public override object ProvideValue(IServiceProvider serviceProvider) { lock (StoreLock) { var storedIcon = StoredIcons.FirstOrDefault(x => x.IconId == IconId && x.Size == Size); if (storedIcon != null) { return(storedIcon.ImageSource); } using ( var extractor = new IconExtractor(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), LibraryName))) using (var icon = extractor.GetIconAt(IconId)) { var info = new IconInfo(icon); var index = info.GetBestFitIconIndex(new Size(Size, Size)); using (var bestIcon = info.Images[index]) { var imageSource = Imaging.CreateBitmapSourceFromHIcon( bestIcon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); StoredIcons.Add(new StoredIcon { IconId = IconId, ImageSource = imageSource, Size = Size }); return(imageSource); } } } }