gpt4 book ai didi

c# - 本地使用 azure 缓存时出现 InvalidOperationException

转载 作者:行者123 更新时间:2023-12-03 04:37:17 26 4
gpt4 key购买 nike

尝试在本地创建 azure 缓存实例时出现 InvalidOperationException(异常和代码如下所示)。该代码正在从控制台应用程序运行。当我在 azure 模拟器中以辅助角色运行它时,它工作得很好。

是否可以使用 azure 缓存而不在模拟器中运行它?

{System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: role discovery data is unavailable
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_Roles()

配置

  <dataCacheClients>
<dataCacheClient name="mycache.cache.windows.net">
<autoDiscover
isEnabled="true"
identifier="mycache.cache.windows.net" />
<securityProperties mode="Message" sslEnabled="false">
<messageSecurity authorizationInfo="[mytoken]=" />
</securityProperties>
</dataCacheClient>
</dataCacheClients>

代码:

        bool autoDiscover = true;
string identifier = "foo";

var cacheFactoryConfiguration = new DataCacheFactoryConfiguration
{
AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(autoDiscover, identifier),
TransportProperties = new DataCacheTransportProperties { MaxBufferSize = int.MaxValue },
IsCompressionEnabled = true,
MaxConnectionsToServer = 3
};

var dataCacheFactory = new DataCacheFactory(cacheFactoryConfiguration);

最佳答案

可以,但不能使用自动发现功能。自动发现是角色内缓存的一项功能,需要 Azure RoleEnvironment(因此您会收到错误)。

// Cache client configured by settings in application configuration file.
DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration("mycache.cache.windows.net");
DataCacheFactory cacheFactory = new DataCacheFactory(config);
DataCache defaultCache = cacheFactory.GetDefaultCache();

// Put and retrieve a test object from the default cache.
defaultCache.Put("testkey", "testobject");
string strObject = (string)defaultCache.Get("testkey");

另外注意 - 我不会在 Azure 共享缓存上进行任何开发 - 该服务将于 2014 年停用 - 请参阅 http://www.windowsazure.com/en-us/pricing/details/cache/

关于c# - 本地使用 azure 缓存时出现 InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19177864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com