【问题标题】:Recomposition not reloading part重组不重新加载部分
【发布时间】:2014-01-17 10:09:25
【问题描述】:

说来话长……抱歉。

我正在使用PartUpdatesInPlace 中的示例并更改代码,以便在从扩展路径中删除它后重新加载 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("回车重新添加原栏"); 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");
    }
}

【问题讨论】:

    标签: c# mef shadow-copy


    【解决方案1】:

    因此,在 Glenn Block(编写 MEF 和示例的人中)的一些帮助下,我们发现问题仅在 VS 中调试此示例并使用相同的 VS 实例(如果使用另一个实例进行重建)时发生Vs 或 Roslyn(我只是为了玩它而尝试这个)它工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多