无法以编程方式在Azure中仅在Azure中创建客户端DataCache

时间:2011-12-20 10:46:13

标签: .net vb.net azure azure-appfabric

我有一个Azure辅助角色,需要在AppFabric中使用缓存。

在本地运行时(Win7x64,VS2010)指向云中的缓存,它运行正常。

当我将同一个软件包部署到云端(再次指向同一个缓存)时,会产生以下异常:

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() 

看了这段代码后,遇到这行代码就会发生这种情况:

Dim configuration As New DataCacheFactoryConfiguration()

此行被击中后无法运行。正如我所说,本地和云之间的配置是相同的。我使用带有凭据的缓存作为Web部署中的会话状态提供程序,因此我相信缓存和访问它是好的。

我的构建计算机安装了November 2011 release of the Azure SDKAzure AppFabric SDK 1.5

获取缓存的方法如下:

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

1 个答案:

答案 0 :(得分:1)

2011年11月发布的SDK包括appfabric .dlls(版本1.6),因此您不再需要为appfabric单独安装SDK。我会尝试浏览你的每个项目,删除对缓存.dll的引用,然后将它们添加回指向... \ Windows Azure SDK \ v1.6 \ Cache \ ref

下的项目。

我发现构建服务器可能会对哪些.dll引用感到困惑。