Asp.net mvc 为什么System.Web.Services.Protocols.LogicalMethodInfo无法在Azure缓存中序列化?

Asp.net mvc 为什么System.Web.Services.Protocols.LogicalMethodInfo无法在Azure缓存中序列化?,asp.net-mvc,web-services,caching,serialization,azure,Asp.net Mvc,Web Services,Caching,Serialization,Azure,使用azure缓存但不使用HttpRuntime时出错。缓存: 无法序列化类型“System.Web.Services.Protocols.LogicalMethodInfo”。考虑使用DATACONTractAttor属性对其进行标记,并标记要使用DATAMEMBAREATE属性序列化的所有成员。如果类型是集合,请考虑用CopyDATAcNoTractAttor标记它。有关其他受支持的类型,请参阅Microsoft.NET Framework文档。 搜索之后,我注意到这篇文章说“HttpRu

使用azure缓存但不使用HttpRuntime时出错。缓存:

无法序列化类型“System.Web.Services.Protocols.LogicalMethodInfo”。考虑使用DATACONTractAttor属性对其进行标记,并标记要使用DATAMEMBAREATE属性序列化的所有成员。如果类型是集合,请考虑用CopyDATAcNoTractAttor标记它。有关其他受支持的类型,请参阅Microsoft.NET Framework文档。

搜索之后,我注意到这篇文章说“HttpRuntime.Cache根本不序列化数据”

示例代码:

protected void Page_Load(object sender, EventArgs e)
{
List<myclass> items = new List<myclass>();
MyClass item1 = new MyClass() { ID = 1 };
items.Add(item1);

HttpRuntime.Cache.Insert("test1", items); //working

DataCache cache = new DataCache("default"); 
cache.CreateRegion("reg");

cache.Put("test2", items, "reg");//error
}

}

public class MyClass
{
public MyClass()
{

Type myType = typeof(MyService);
MethodInfo myMethodInfo = myType.GetMethod("Add");
_log = new **LogicalMethodInfo**(myMethodInfo);
}
public int ID { get; set; }
public **LogicalMethodInfo** _log;
}

public class MyService
{
public int Add(int xValue, int yValue)
{
return (xValue + yValue);
}
}
受保护的无效页面加载(对象发送方,事件参数e)
{
列表项=新列表();
MyClass item1=新的MyClass(){ID=1};
增加(第1项);
HttpRuntime.Cache.Insert(“test1”,items);//正在工作
数据缓存=新数据缓存(“默认”);
cache.CreateRegion(“reg”);
cache.Put(“test2”,items,“reg”);//错误
}
}
公共类MyClass
{
公共MyClass()
{
类型myType=typeof(MyService);
MethodInfo myMethodInfo=myType.GetMethod(“添加”);
_log=new**LogicalMethodInfo**(myMethodInfo);
}
公共int ID{get;set;}
公共**逻辑方法信息**\u日志;
}
公共类MyService
{
公共整数相加(整数xValue,整数yValue)
{
返回值(xValue+yValue);
}
}

您收到该错误是因为
System.Web.Services.Protocols.LogicalMethodInfo
不可序列化。为了添加到Azure缓存中,必须序列化对象并通过网络发送到缓存服务器。显然,这不能用不可序列化的对象来完成
HttpRuntime.Cache
是内存中的数据存储。因为它在内存中,所以不需要序列化对象,因此不关心缓存的对象是否可序列化

请学习使用降价