Problem with Recomposition

Jan 6, 2010 at 4:40 PM

Hi! I'm trying to write a small application where the user can add and remove plugins at runtime.
When the user has selected the plugin I add it to the AggregateCatalog

catalog.Catalogs.Add(new AssemblyCatalog(filename))

Then in the container's ExportsChanged event handler I do

private void container_ExportsChanged(object sender, ExportsChangeEventArgs e)
        {
            foreach (var ex in e.AddedExports)
            {
                if (ex.Metadata.ContainsKey("ExportTypeIdentity"))
                {
                    this.Plugins.Add((IPlugin)(ex.Metadata["ExportTypeIdentity"] as Export).Value);
                }
            }
        }

But ex.Metadata["ExportTypeIdentity"] contains a string and so the cast fail.

Ah when I add the new plugin to the catalog the Plugins collection is not updated and I've set the AlloweRecomposition to true

[ImportMany(AllowRecomposition = true)]
        public ObservableCollection<IPlugin> Plugins { get; set; }

Any idea?

Thanks
Federico