.net 无法仅在云中以编程方式在Azure中创建客户端数据缓存
我有一个Azure worker角色,需要使用AppFabric中的缓存 当本地运行(Win7x64,VS2010)指向云中的缓存时,它工作正常 当我将相同的包部署到云时(再次指向相同的缓存),它会产生以下异常:.net 无法仅在云中以编程方式在Azure中创建客户端数据缓存,.net,vb.net,azure,azure-appfabric,.net,Vb.net,Azure,Azure Appfabric,我有一个Azure worker角色,需要使用AppFabric中的缓存 当本地运行(Win7x64,VS2010)指向云中的缓存时,它工作正常 当我将相同的包部署到云时(再次指向相同的缓存),它会产生以下异常: Message: The type initializer for 'Microsoft.ApplicationServer.Caching.DataCacheClientLogManager' threw an exception. Exception Type:
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部署中的会话状态提供程序,因此我相信缓存和对它的访问都很好
我的生成计算机具有,并已安装
获取缓存的方法如下所示:
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
2011年11月发布的SDK包括appfabric.dll(版本1.6),因此您不再需要仅为appfabric安装单独的SDK。我将尝试浏览您的每个项目,删除对caching.dll的引用,并将它们添加回指向…\Windows Azure SDK\v1.6\Cache\ref下的项目
我发现构建服务器可能会对引用哪个.dll感到困惑。谢谢-这让我回顾了哪些dll的复制本地设置为false。最后,我将Microsoft.WindowsFabric.Common和Microsoft.WindowsFabric.Data.Common的“复制本地”设置设置设置为true,并且现在所有功能都可以正常工作了。我以前从未遇到过的其他帮助是此实用程序,它会将您的项目文件与Azure操作系统中的当前程序集进行比较。我想这会是未来的救命恩人:@alergy我也犯了同样的错误,但没有处理azure。读了你的评论后,我把那些DLL丢进了垃圾箱,一切都正常了!谢谢:)