无法从不同的应用程序读取蔚蓝的缓存数据 [英] unable to read azure cached data from a different application

查看:115
本文介绍了无法从不同的应用程序读取蔚蓝的缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下code做蔚蓝的缓存,它工作正常...

I am using following code to do azure-caching and it works fine...

[Serializable]
public class Person
{
    public string First { set; get; }
    public string Last { set; get; }

}

[TestClass]
public class AzureCachingTests1
{
    private static DataCacheFactory _factory;

    [TestInitialize]
    public void Setup()
    {

        _factory = new DataCacheFactory(new DataCacheFactoryConfiguration("mycache"));
    }


    [TestMethod]
    public void TestMethod1()
    {

        DataCache cache = _factory.GetDefaultCache();

        var person = new Person { First = "Jane", Last = "doe" };
        const string key = "mykey";

        cache.Put(key, person, TimeSpan.FromMinutes(10));
        var data = (Person)cache.Get(key);
        Assert.AreEqual("Jane", data.First);

    }
}

现在在Visual Studio中的另一个实例,我运行下面的code ...

Now in another instance of Visual studio, I run the following code...

[TestClass]
public class AzureCachingTests
{
    private static DataCacheFactory _factory;
    [TestInitialize]
    public void Setup()
    {

        _factory = new DataCacheFactory(new DataCacheFactoryConfiguration("mycache"));
    }


    [TestMethod]
    public void TestMethod1()
    {

        DataCache cache = _factory.GetDefaultCache();
        const string key = "mykey";
        var data = (Person) cache.Get(key);  <----- Error here... <--------
        Assert.AreEqual("Jane", data.First);

    }
}

[Serializable]
public class Person
{
    public string First { set; get; }
    public string Last { set; get; }

}

这一次,我碰到下面的错误...

This time, I get the following error...

试验方法AzureCaching.AzureCachingTests.TestMethod1抛出异常:
System.Runtime.Serialization.SerializationException:大会'AzureCaching1,版本= 1.0.0.0,文化=中立,公钥=空'未找到

Test method AzureCaching.AzureCachingTests.TestMethod1 threw exception: System.Runtime.Serialization.SerializationException: Assembly 'AzureCaching1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not found.

我的类人是Serializable接口。为什么我不能够查询在AzureCaching缓存我在AzureCaching1 ??

My class Person is Serializable. Why am I not able to query for the cache in AzureCaching that I cached in AzureCaching1 ??

请帮忙。谢谢

推荐答案

除非你引用的项目AzureCachingTests1是,你的测试已经不知道如何反序列化,它是从缓存中检索的项目。你必须具有相同的名称和相同的属性两班,但它们不是同一类。

Unless you've referenced the project AzureCachingTests1 is in, your test has no idea how to deserialize the item that it is retrieving from the cache. You have two classes that have the same name and the same properties, but they're not the same class.

由于这个你写的测试,你需要参考项目AzureCachingTests1是从AzureCachingTests是项目和删除AzureCachingTests项目个人类定义(并确保你投射到正确的类为好)。

Because this you're writing tests, you'll need to reference the project AzureCachingTests1 is in from the project that AzureCachingTests is in and delete the class definition for Person in the AzureCachingTests project (and make sure you're casting to the right class as well).

如果这不是一个测试,你只是想给两个或多个项目的最好的办法是有一个包含了所有常见的两种类的第三个项目之间共享的一类,在这种情况下,它仅仅是Person类。

If this wasn't a test and you just wanted to share a class between two or more projects the best idea is to have a third project that contains all of the classes that are common to both, in this case it's just the Person class.

这篇关于无法从不同的应用程序读取蔚蓝的缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆