C# 添加Windows Azure缓存会导致Visual Studio 2012崩溃,datacachefactory参数为null异常

C# 添加Windows Azure缓存会导致Visual Studio 2012崩溃,datacachefactory参数为null异常,c#,caching,azure,azure-caching,C#,Caching,Azure,Azure Caching,我已将Windows Azure Cache 1.8.0 nuget包添加到我的解决方案中,但在加载项目时,它最终导致Visual studio崩溃。我发现,通过从bin文件夹中删除dll,然后在项目加载时VisualStudio将它们添加回bin,可以“防止”崩溃 我要删除的DLL有: Microsoft.ApplicationServer.Caching.AzureClientHelper.dll Microsoft.ApplicationServer.Caching.AzureCommon

我已将Windows Azure Cache 1.8.0 nuget包添加到我的解决方案中,但在加载项目时,它最终导致Visual studio崩溃。我发现,通过从bin文件夹中删除dll,然后在项目加载时VisualStudio将它们添加回bin,可以“防止”崩溃

我要删除的DLL有:

Microsoft.ApplicationServer.Caching.AzureClientHelper.dll
Microsoft.ApplicationServer.Caching.AzureCommon.dll
Microsoft.ApplicationServer.Caching.Client.dll
Microsoft.ApplicationServer.Caching.Core.dll
当我查看visual studio崩溃的事件查看器时,我发现:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
    Stack:
    at System.Threading.Monitor.Enter(System.Object)
    at Microsoft.ApplicationServer.Caching.DataCacheFactory.Close()
    at Microsoft.ApplicationServer.Caching.DataCacheFactory.Finalize()
我不确定为什么VS在加载项目时使用DLL,但我承认我不是这方面的专家

我基本上遵循了本页所述的过程,为缓存添加了一个专用的缓存工作者角色:

我尝试过删除并重新安装该软件包,删除并重新安装Visual Studio SDK(2012年10月),但问题再次出现

另外,我没有安装应用程序结构服务器


提前感谢您的帮助

我们可能需要捕获visual studio进程(devenv.exe)的转储,以查看导致此异常的原因。您可以使用debugdiag(“”)捕获转储。
您可能需要Microsoft支持服务(“”)来进一步调查此问题,因为异常来自缓存代码本身。

如果其他人遇到此问题,我将在这里提供似乎对我有用的内容

为了让VisualStudio加载项目,我从项目中删除了DLL。我也在项目加载时删除了它们,并将DLL放回了bin文件夹中

我删除了对DLL的引用。然后,我删除了使用datacachefactory的代码

最后,我认为这是由于在我的代码中不正确地使用了缓存造成的,我在缓存上执行了构建。我能够纠正它的用法,构建解决方案,并将所有DLL恢复到项目中

以前由datacache创建的对象不是静态的

以下是我对datacache工厂的正确用法:

using System;
using Microsoft.ApplicationServer.Caching;


namespace WebRole1.Classes
{
    public class AzureCache
    {
        public static DataCache cache { get; set; }
        public static DataCacheFactory dataCacheFactory { get; set; }

    public AzureCache()
    {
        if (cache == null){
            DataCacheFactoryConfiguration cfg = new DataCacheFactoryConfiguration();
            cfg.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, "CacheWorkerRole1"); 
            dataCacheFactory = new DataCacheFactory(cfg);
            cache = dataCacheFactory.GetDefaultCache();
        }
    }

    public void Add(string item, object value)
    {                                                                              
       cache.Add(item, value);
    }
    public void Add(string item, object value, TimeSpan timeout)
    {
       cache.Put(item, value, timeout);
    }
    public object Get(string item)
    {   
        return cache.Get(item);
    }

    public TimeSpan TimeRemaining (string item)
    {
        DataCacheItem DCitem = cache.GetCacheItem(item);
        return DCitem.Timeout;
    }

    public void Flush()
    {
        cache.Clear();
        DataCacheFactory cacheFactory = new DataCacheFactory();
        cache = cacheFactory.GetDefaultCache();

    }

    }
}

这不是一个专门与VisualStudio相关的问题。我在运行我的webrole时得到它。 退房