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);
}
}
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…
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.
My class Person is Serializable. Why am I not able to query for the cache in AzureCaching that I cached in AzureCaching1 ??
Please help. thanks
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.
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).
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.