Assembly Caching Error

Mar 7, 2009 at 4:02 PM
Hi,

I have been playing around with catalog caching based on an example from discussion:41362
With preview 4 the code example no longer works and I have created the following code....

var catalog = new AggregateCatalog();
AssemblyName _an = Assembly.GetExecutingAssembly().GetName();
String cacheCatalogPath = String.Format(@"{0}\MEFCache", Environment.CurrentDirectory);
String cacheCatalogFile = String.Format(@"{0}\{1}.dll", cacheCatalogPath, _an.Name);
if(File.Exists(cacheCatalogFile)) {
catalog.Catalogs.Add(ComposablePartCatalogCachingServices.ReadCatalogFromCache(cacheCatalogFile));
} else {
catalog.Catalogs.Add(new DirectoryCatalog(Environment.CurrentDirectory));
ComposablePartCatalogCachingServices.CacheCatalog(catalog, cacheCatalogFile);
}

however during the second run through I get the following error when trying to read from the cached dll

Message
Invalid cache : type 'EntryPoint' is not found.

StackTrace
at System.ComponentModel.Composition.Caching.ComposablePartCatalogAssemblyCacheReader.GetCacheType(Assembly assembly, String name)
at System.ComponentModel.Composition.Caching.ComposablePartCatalogAssemblyCacheReader..ctor(Assembly cacheAssembly)
at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCachingServices.ReadCatalogFromCache(AssemblyName assemblyName)
at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCachingServices.ReadCatalogFromCache(String assemblyPath)
at MungleFish.Presenter.Player..ctor() in C:\Users\frazer\Documents\Backup\MEF_20090228.2\Presenter\MungleFish.Presenter.Player\Window1.xaml.cs:line 184


The dll appears to be been created correctly and the file path for the read is pointing to the dll.

Where am I going wrong?

Many Thanks

Frazer
Mar 9, 2009 at 3:06 PM
Did you have an existing cache (dll file) created using the previous version of MEF?

One issue I ran into is that the cache files from prior versions of MEF are not compatible - so you have to make sure you delete any existing cache files and then recreate them using the new version.

No idea if this is what you're running into, but it's a thought.

Phil

Mar 9, 2009 at 8:43 PM
Hi Phil,

not so simple i'm affraid :-(

This was a clean build with no prior dll in existance.

Thanks

Frazer
Mar 9, 2009 at 9:01 PM
Hmm.  Have you taken a look at the created cache assembly with reflector?  Might be worth a look...

From what I can see of my cache assemblies, there is indeed a public static class named 'EntryPoint' in the assembly.

It might be worth checking to see if your cache assembly has this.  I would guess if that doesn't exist then it's *probably* some issue related to creation of the cache.  I know that's not very helpful, but it might help narrow it down a little.

Regards,
Phil
Mar 9, 2009 at 9:14 PM
I assume there are some actual exports in the directory catalog?  Just wondering if it's doing something weird like not creating an entry point if it doesn't find any exports.

Phil

Mar 18, 2009 at 9:54 PM
Hi Phil,

sorry for the delay, the time vampires have been at me again ;-(

Reflector shows there is a class named EntryPoint.

What I have noticed is that none of the following classes are populated
ImportDefinitions
ExportDefinitions
PartDefinitions

I assume this is because I am using lazy loading i.e.

_container =

new CompositionContainer(catalog);

 

_logger = _container.GetExportedObjectOrDefault<

ILogger>();

and the catalog never actually contains any interfaces.

I have got it to work using

 

catalog.Catalogs.Add(

new DirectoryCatalog(Environment.CurrentDirectory));

before I create the cache.

Is there any way to utilise both lazy loading and caching?

Many Thanks

Frazer

 

Mar 18, 2009 at 10:28 PM
Hi guys

I wanted to give you an FYI (based on the fact that you are using our existing caching) that we are changing the caching story in our next drop. We've removed the caching APIs and are replacing them with a set of APIs that make it very easy to provide MEF information from a cache or otherwise that it can use to manufacture part definitions. Our next drop will be in a few weeks so you should be able to see it there.

Thanks
Gelnn
Mar 21, 2009 at 10:56 PM
Hi Glenn,

Thanks for this.  I will eagerly await your next drop.

Keep up the good work

Frazer