Recomposition not reloading part

146 views Asked by At

A bit of a long story... sorry.

I am using the example from PartUpdatesInPlace and changing the code so that I can reload Extensions1.dll after deleting it from the Extensions path.

I set a breakpoint after deleting Extensions1.dll, change Bar it so it returns a different string recompile and then refresh the catalog in the hope that when OnImportsStatisfied run, it will return the updated string, however it doesn't.

As per original, ShadowCopyAssembly is enabled.

/// setup catalogs and container and instance of BarWatcher
  Console.WriteLine("Press enter to add a new bar");
        Console.ReadLine();
        //copy in a bar and refresh
        File.Copy(BinDir + @"..\..\..\PartUpdatesInPlaceExtensions2\bin\debug\PartUpdatesInPlaceExtensions2.dll", ExtensionsPath + "Extensions2.dll");
        directoryCatalog.Refresh();

        Console.WriteLine("Press enter to remove the first bar");
        Console.ReadLine();
        //delete the original bar and refresh
        File.Delete(ExtensionsPath + "Extensions1.dll");
        directoryCatalog.Refresh();

//set breakpoint line below Console.WriteLine("Press enter to add the original bar again"); Console.ReadLine(); //copy in a bar and refresh File.Copy(BinDir + @"......\PartUpdatesInPlaceExtensions\bin\debug\PartUpdatesInPlaceExtensions.dll", ExtensionsPath + "Extensions1.dll"); directoryCatalog.Refresh();

        container.Compose(batch);
        Console.ReadLine();

I can add all the code to a repository if it would make this simpler. My version of 'Microsoft.Composition' is 1.0.20 (got it of Nuget)

Any ideas why this is happening?

As far as I understand the recomposition should happen because it's enabled in BarWatcher

    [Export]
public class BarWatcher : IPartImportsSatisfiedNotification
{
    [ImportMany(AllowRecomposition = true)]
    public IEnumerable<IBar> Bars { get; set; }

    public void OnImportsSatisfied()
    {
        if (Bars.Any())
        {
            foreach (var bar in Bars)
                Console.WriteLine("bar-"+bar.Foo());
        }
        else
            Console.WriteLine("No Bars present");

        Console.WriteLine("\n");
    }
}
1

There are 1 answers

0
roundcrisis On BEST ANSWER

So, with some help from Glenn Block(on of the guys that wrote MEF and the sample) and we figured that the problem occurred only when debugging this sample in VS and rebuilding with the same instance of VS if rebuilding with another instance of Vs or Roslyn(I was trying this just to play with it) it works out ok.