【问题标题】:Loading Delay Signed assemblies in MEF在 MEF 中加载延迟签名的程序集
【发布时间】:2014-03-04 18:25:14
【问题描述】:

我在以下路径中有一个 Windows 服务设置:

C:\Avalanche\Services\Avalanche.EXE
C:\Avalanche\Services\Core.DLL

Core.DLL 很重要。它是延迟签名的;它包含要为任何插件导出的接口

接下来,我有一个插件文件夹:

C:\Avalanche\Snowballs\

我在这里放入的插件是延迟签名的,并且是针对正确版本的 Core.DLL 构建的,与 Services 文件夹中的版本相同。

我的问题是,在运行时,MEF 似乎根本看不到插件。它加载它们,但似乎无法用它做任何事情。但如果我不签任何东西,那么就没有问题。我签署插件的原因是出于版本原因。如果我制作插件的 v1 并安装它,然后构建同一插件的 v2 并安装它(不反弹服务),MEF 将加载 v1 两次;这不是我想要的。这通常不是问题,但此服务旨在保持相当长的一段时间(一次数天、数月)。

如何让 MEF 查看这些延迟签名的程序集?它似乎连它们都没有捡起来。

注意:我已经尝试不对程序集进行延迟签名。这会产生 FileLoadException。我还注册了用于跳过验证的程序集(通过 sn 并让它还导出我已安装的 reg 文件)。

这是加载插件的 Core.DLL 中的代码。

// Setup
iCatalog = new AggregateCatalog();
iWatcher = new List<FileSystemWatcher>();
List<DirectoryCatalog> oDirectories = new List<DirectoryCatalog>();

// Make sure all the folders exist; add them to the aggregate catalog.
// NOTE: aLocations is a string[] of directories that are to be used.
foreach (String sFolder in aLocations)
{
if (Directory.Exists(sFolder))
    {
        DirectoryCatalog oDirectoryCatalog = new DirectoryCatalog(sFolder);
        iCatalog.Catalogs.Add(oDirectoryCatalog);        
        oDirectories.Add(oDirectoryCatalog);
    }
}

iDirectories = oDirectories as IEnumerable<DirectoryCatalog>;

// Now then, create our CompositionContainer and compose the parts
iContainer = new CompositionContainer(iCatalog);
iContainer.ComposeParts(this);

这是一个示例插件:

[Export(typeof(Core.Contracts.ISnowballPlugin))]
public class CSharpSample : Core.Contracts.ISnowballPlugin
{
    private CSharpSampleSnowball iSnowball = new CSharpSampleSnowball();
    public Core.Snowball.Snowball Snowball
    {
        get { return iSnowball; }
    }

    public TimeSpan Frequency
    {
        get { return TimeSpan.FromSeconds(2); }
    }

    public string Grouping
    {
        get { return "None"; }
    }

    public TimeSpan? Timeout
    {
        get { return null; }
    }
}

public class CSharpSampleSnowball : Core.Snowball.Snowball
{
    public CSharpSampleSnowball()
        : base("CSharp Example Version 2.0", "An example C# snowball")
    {

    }

    protected override void Run()
    {
        return;
    }
}

【问题讨论】:

    标签: c# .net mef


    【解决方案1】:

    好的。我暂时解决了解决方案。插件已签名的事实似乎有点牵强。

    Core.DLL 被签名比插件被签名是一个更大的问题。 Core.DLL 文件未能正确加载(如果有的话)。因此,在这一事实之后的所有其他事情都有待辩论和质疑。

    目前,我使用 sn.exe 跳过对 Core.DLL 的验证。我将其标记为现在的答案。我想知道为什么我必须跳过对 Core.DLL 的验证;是不是因为EXE也没有签名?

    【讨论】:

      猜你喜欢
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多