Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正在为Cmdlet添加配置文件_C#_Powershell_Appfabric_Cmdlets - Fatal编程技术网

C# 正在为Cmdlet添加配置文件

C# 正在为Cmdlet添加配置文件,c#,powershell,appfabric,cmdlets,C#,Powershell,Appfabric,Cmdlets,我制作了一个powershell Cmdlet,用于创建AppFabric a区域,代码为: [Cmdlet(VerbsCommon.New, "CacheRegion")] public class NewCacheRegion : Cmdlet { [Parameter(Mandatory = true, Position = 1)] public string Cache { get; set; } [Parameter(Mandatory = true

我制作了一个powershell Cmdlet,用于创建AppFabric a区域,代码为:

    [Cmdlet(VerbsCommon.New, "CacheRegion")]

public class NewCacheRegion : Cmdlet {
    [Parameter(Mandatory = true, Position = 1)]
    public string Cache { get; set; }

    [Parameter(Mandatory = true, Position = 2)]
    public string Region { get; set; }

    protected override void ProcessRecord() {
        base.ProcessRecord();

        DataCacheFactory factory = new DataCacheFactory(); // exception

        DataCache cache = factory.GetCache(Cache);

        try {
            cache.CreateRegion(Region);
        }
        catch (DataCacheException ex) {}
    }
}
它与导入模块appfabriccmdlet.dll一起安装,代码在运行新的cacheregion时执行

但是这条线

DataCacheFactory factory = new DataCacheFactory();
引发服务器集合为空的异常,这意味着在app.config中找不到dataCacheClient节。所以我想要一个客户端,但我不确定在哪个配置文件中添加appfabric部分。我已尝试从cmdlet dll运行的可执行文件中查找

Assembly a = Assembly.GetEntryAssembly();
但它返回空值

那么,我需要将cmdlet dll有权访问的配置部分放在哪里呢?

没关系

通过编程方式添加不带配置的服务器修复了此问题

        DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
        servers[0] = new DataCacheServerEndpoint("localhost", 22233);

        DataCacheFactoryConfiguration conf = new DataCacheFactoryConfiguration();

        conf.Servers = servers;

        DataCacheFactory factory = new DataCacheFactory(conf);