Using the procedure described in the following SO answer and with the help of ILSpy I've been able to understand why this exception occurs: in Windows Azure Caching 2.1 when the role specified in the client configuration is not found it is considered an address and execution continues, while in older versions it throws an exception (which I caught to understand cache was not enabled).
The relevant log messages are:
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.
and
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
To resolve this issue you can:
- analize the
DataCacheFactory
just created and see if in theServers
property there is any item in which the address is the same as the name of the cache role -- a sign that the indicated role has no cache configured; - in debug configurations of the hosted service lower the number of retries in the
CacheReadyRetryPolicy
property of theDataCacheFactory
(which was causing the 3 minute delay before the exception) and if exceptions are thrown assume that the cache is unavailable.