I have a Azure worker role that needs to use the cache in AppFabric.
When run locally (Win7x64,VS2010) pointing at the cache in the cloud, it works fine.
When I deploy the same package to the cloud (again pointing at the same cache), it produces the following exception:
Message: The type initializer for 'Microsoft.ApplicationServer.Caching.DataCacheClientLogManager' threw an exception.
Exception Type: TypeInitializationException
StackTrace: Microsoft.ApplicationServer.Caching.DataCacheClientLogManager.Initialize(DataCacheLogSink logSink)
at Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration.Initialize(String clientName)
at CommunicationRole.CacheUtil.GetCache()
Having looked at the code, this is happening when this line of code is hit:
Dim configuration As New DataCacheFactoryConfiguration()
Nothing runs after this line is hit. As I've said, the configs between local and cloud are the same. I use the cache with the credentials as a session state provider in a web deployment so I believe the cache and access to it are good.
My build machine has the November 2011 release of the Azure SDK, and Azure AppFabric SDK 1.5 installed.
The method to get the cache is as follows:
Imports System.IO
Imports Microsoft.WindowsAzure
Imports Microsoft.WindowsAzure.ServiceRuntime
Imports Microsoft.WindowsAzure.StorageClient
Imports Microsoft.ApplicationServer.Caching
Imports System.Security
Public Class CacheUtil
Private Shared _factory As DataCacheFactory = Nothing
Private Shared _cache As DataCache = Nothing
Public Shared Function GetCache() As DataCache
If _cache IsNot Nothing Then
Return _cache
End If
'-------------------------
' Configure Cache Client
'-------------------------
'Define Array for 1 Cache Host
Dim servers As New List(Of DataCacheServerEndpoint)()
'Specify Cache Host Details
' Parameter 1 = host name
' Parameter 2 = cache port number
servers.Add(New DataCacheServerEndpoint(RoleEnvironment.GetConfigurationSettingValue("hostName"), Int32.Parse(RoleEnvironment.GetConfigurationSettingValue("cachePort"))))
' Setup secure key
Dim strACSKey As String = RoleEnvironment.GetConfigurationSettingValue("authorisationToken")
Dim secureACSKey As New SecureString
For Each a As Char In strACSKey
secureACSKey.AppendChar(a)
Next
secureACSKey.MakeReadOnly()
Dim factorySecurity As New DataCacheSecurity(secureACSKey)
'Create cache configuration
Dim configuration As New DataCacheFactoryConfiguration()
configuration.Servers = servers
configuration.SecurityProperties = factorySecurity
'Disable tracing to avoid informational/verbose messages on the web page
DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off)
'Pass configuration settings to cacheFactory constructor
_factory = New DataCacheFactory(configuration)
'Get reference to named cache called "default"
_cache = _factory.GetCache(RoleEnvironment.GetConfigurationSettingValue("cacheName"))
Return _cache
End Function
Public Shared Sub Dispose()
If _factory IsNot Nothing Then
_factory.Dispose()
End If
End Sub
End Class
The November 2011 release of the SDK includes the appfabric .dlls (version 1.6) so you no longer need the separate SDK install just for appfabric. I would try going through each of your projects, removing the references to the caching .dlls and add them back in pointing to the ones under ...\Windows Azure SDK\v1.6\Cache\ref
I've found that build servers can get confused about which .dlls to reference.