This project has moved and is read-only. For the latest updates, please go here.

Error when using CachedAggregateCatalog

Sep 19, 2009 at 7:57 PM

Hi Guys,

I have been playing around with the caching sample from the recent MEF 7 release and have partially got it working.


var testAssemblyCatalog = new CachedAssemblyCatalog(new DirectoryInfo(@".\Test.dll").FullName);

                    ComposablePartCatalogCachingServices.CacheCatalog(testAssemblyCatalog, new DirectoryInfo(@".\AssemblyCache.dll").FullName);


var cachedAssemblyCatalog = ComposablePartCatalogCachingServices.ReadCatalogFromCache(new DirectoryInfo(@".\AssemblyCache.dll").FullName);


This example works fine, but the catalog I want to work with is a DirectoryCatalog that has 7 MEF dlls in it.  I have tried the following code but it throws an error...


var testAggregateCatalog = new CachedAggregateCatalog(new ComposablePartCatalog[] { new DirectoryCatalog(Environment.CurrentDirectory) });

                    ComposablePartCatalogCachingServices.CacheCatalog(testAggregateCatalog, new DirectoryInfo(@".\AggregateCache.dll").FullName);


var cachedAggregateCatalog = ComposablePartCatalogCachingServices.ReadCatalogFromCache(new DirectoryInfo(@".\AggregateCache.dll").FullName);


The error comes from the CachedAggregateCatalog.cs(149) after we try to cast the ComposablePartCatalog as an ICachedComposablePartCatalog and it returns null.


foreach (ComposablePartCatalog catalog in this.Catalogs){

ICachedComposablePartCatalog cachedCatalog = catalog as ICachedComposablePartCatalog;

if (cachedCatalog == null) {

throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Strings.CatalogIsNotCacheable, catalog.GetType()));




Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "Microsoft.Internal.Strings.resources" was correctly embedded or linked into assembly "Caching" at compile time, or that all the satellite assemblies required are loadable and fully signed.


As far as i can tell this will never cast as it is the CachedAggregateCatalog class that inherits the ICachedComposablePartCatalog interface not the ComposablePartCatalog class, which only inherits the IDisposable interface.


Is there another way to cache an aggregate catalog?


Thanks in advance



Sep 20, 2009 at 6:55 AM

Unfortunately there isn't a Cached version of the DirectoryCatalog provided in this sample so it cannot be used directly. The only catalogs that can be cached are the ones provided in the Caching sample and they all begin with "Cached". To work around this you try to use a CachedAggregateCatalog with a set of CachedAssemblyCatalogs or try and write a CachedDirectoryCatalog.

Sep 21, 2009 at 9:44 PM

Hi weshaggard,

I decided to go with the CachedAssemblyCatalogs in a CachedAggregateCatalog, this has dropped my launch time from 1.8s to 1.3, a very worthy performance gain :-D

Are you intending to write the CachedDirectoryCatalog?  I notice the other 3 catalogs are done.

Thanks for your pointer



Sep 21, 2009 at 10:47 PM

I don't think there are currently any plans to write CachedDirectoryCatalog, at least not at this point. We primarily released the caching sample as a proof of concept sample to demonstrate for others how you could implement caching on top of MEF.

Feel free to try and implement it yourself in the caching sample along side the other cached* catalogs.


Sep 25, 2009 at 2:40 PM

FYI you can make a small change to the Strings.Designer.cs file in the Caching project to get the actual useful error message, this will help in other areas as well.

Change the string literal "Microsoft.Internal.Strings" on line 42 to "Caching.Strings"

The reason it is broken is because I am assuming that the caching code is part of the main System.Composition project internally so when they created the public sample they didn't change the assembly base namespace which confuses the designer generated code.