有点长故事......抱歉。
我正在使用PartUpdatesInPlace中的示例并更改代码,以便在从Extensions路径中删除Extensions1.dll后可以重新加载它。
我在删除Extensions1.dll后设置断点,更改 Bar ,以便它返回不同的字符串重新编译,然后刷新目录,希望当 OnImportsStatisfied 运行时,它将返回更新后的字符串,但不会。
根据原始版本,启用了ShadowCopyAssembly。
/// 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();
//在下面设置断点线 Console.WriteLine(“按Enter键再次添加原始栏”); 到Console.ReadLine(); //复制到栏中并刷新 File.Copy(BinDir + @“...... \ PartUpdatesInPlaceExtensions \ bin \ debug \ PartUpdatesInPlaceExtensions.dll”,ExtensionsPath +“Extensions1.dll”); directoryCatalog.Refresh();
container.Compose(batch);
Console.ReadLine();
我可以将所有代码添加到存储库中,如果它可以使这更简单。我的'Microsoft.Composition'版本是1.0.20(得到了Nuget)
为什么会发生这种情况?
据我所知,recomposition应该发生,因为它已在 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");
}
}
答案 0 :(得分:0)
所以,在Glenn Block(编写MEF和示例的人)的帮助下,我们发现只有在VS中调试此示例并使用相同的VS实例重建时才会出现问题,如果使用其他实例进行重建Vs或Roslyn(我试过这个只是为了玩它)它运作正常。