今天我写的订单处理系统报了个奇怪的null引用错误,错误内容如下:
type=System.NullReferenceException
msg=Object reference not set to an instance of an object.
extMsg=
stack=
at PinRui.EDiner2SDK.SDKBLL.RevHistoryManage.<>c__DisplayClass7.b__6(ShopOrderHistory item) in E:\work\src\EDiner2SDK\EDiner2Manage\RevHistoryManage.cs:line 83
at System.Collections.Generic.List1.Find(Predicate
1 match)
at PinRui.EDiner2SDK.SDKBLL.RevHistoryManage.GetOrder(Int32 accountId, String shopOrderNo) in E:\work\src\EDiner2SDK\EDiner2Manage\RevHistoryManage.cs:line 83
at ClientOrder.SendOrderData()
at ClientOrder.ProcessRequest(HttpContext context)
之所以说奇怪是因为,按此报错的来看,应该集合对象为null。但是此集合对象是实例对象,且此类为单件模式。这个集合怎么可能为null呢?实在是不明白这里的问题,忘大家指点一下,谢谢!
下面是这个集合和类的声明方式:
public class RevHistoryManage
{
private static readonly object _lock = new object();
private static RevHistoryManage _instance;
/// <summary>
/// 获取本类唯一实例
/// </summary>
/// <returns></returns>
public static RevHistoryManage Instance()
{
if (_instance == null)
{
lock (_lock)
{
if (_instance == null)
{
_instance = new RevHistoryManage();
}
}
}
return _instance;
}
/// <summary>
/// 构造函数
/// </summary>
private RevHistoryManage()
{
}
private List<ShopOrderHistory> _OrderCacheList = new List<ShopOrderHistory>();
public ShopOrderHistory GetOrder(int orderid)
{
return _OrderCacheList.Find(item => item.orderid == orderid);//就是这行报的错
}
}