0

我有一个 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 部署中使用带有凭据的缓存作为会话状态提供程序,因此我相信缓存和对它的访问是好的。

我的构建机器安装了2011 年 11 月发布的 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
4

1 回答 1

1

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

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

于 2011-12-21T02:05:15.543 回答