使用以下SO 答案中描述的过程并在 ILSpy 的帮助下,我已经能够理解为什么会发生此异常:在 Windows Azure 缓存 2.1 中,当找不到客户端配置中指定的角色时,它被视为地址并执行继续,而在旧版本中它会引发异常(我发现它以了解缓存未启用)。
相关的日志消息是:
WaWorkerHost.exe Information: 0 : INFORMATION:
<DistributedCache.CacheFactory.1> TryAutoDiscoverServersWithinDeployment
for Instance 'WebRole' failed to connect as RoleName type with exception
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. --->
Microsoft.ApplicationServer.Caching.DataCacheException:
ErrorCode<UnspecifiedErrorCode>:SubStatus<ES0001>:The role WebService
was not found in the current deployment.
at Microsoft.ApplicationServer.Caching.AzureClientHelper.RoleUtility.
GetCacheRoleIPList(String roleName, String portIdentifier)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments,
Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.ApplicationServer.Caching.DataCacheFactory.
AutoDiscoverServersWithinDeployment()
at Microsoft.ApplicationServer.Caching.DataCacheFactory.
TryAutoDiscoverServersWithinDeployment()
Assuming it as EndPoint.
和
WaWorkerHost.exe Warning: 0 : WARNING: <DistributedCache.SocketClientChannel.1>
Request 1 to host net.tcp://webrolw:24233/ failed
Status=ChannelOpenFailed[System.Net.Sockets.SocketException (0x80004005):
No such host is known
要解决此问题,您可以:
- 分析
DataCacheFactory
刚刚创建的,查看Servers
属性中是否有地址与缓存角色名称相同的项目——表明指定角色没有配置缓存;
- 在托管服务的调试配置中,降低
CacheReadyRetryPolicy
属性中的重试次数DataCacheFactory
(这导致异常发生前的 3 分钟延迟),如果抛出异常,则假定缓存不可用。