在我的应用程序中抛出了几次ArgumentNullException
,但没有提供任何参数名称。这仅在生产中发生(在脚本服务中引发异常,由 javascript 调用)。我试图在 StackTrace 指向的代码片段中重现这种错误,但ArgumentNullException
我能够重现的每个错误都在其消息中包含了一些参数名称。
所以,我的问题是有没有人知道在ArgumentNullException
没有提供参数名称的情况下何时抛出?或者什么方法最终会触发这个异常?
脚本服务是关于从应用程序缓存中获取一些信息:
private Dictionary<int, MyType> CachedDictionary
{
get
{
//return the Item from the application cache
return GetItem() as Dictionary<int, MyType>;
}
set
{
//adds the Item to the application cache
//with sliding expiration of X minutes
AddItem(value);
}
}
public List<MyType> Get(List<int> idsToRead)
{
List<int> idsNotCached = idsToRead.Except<int>(CachedDictionary.Keys.ToList<int>()).ToList<int>();
if (idsNotCached.Count > 0)
{
//Exception stack trace points to next line:
MyTypeCollection DBitems = BusinessLayer.StaticLoadFromDB(idsNotCached);
lock (CachedDictionary)
{
foreach (MyType item in DBitems)
if (!CachedDictionary.ContainsKey(item.ID))
CachedDictionary.Add(item.ID, item);
}
}
return CachedDictionary.Where(p => idsToRead.Contains(p.Key)).Select(p => p.Value).ToList<MyType>();
}
public static MyTypeCollection StaticLoadFromDB(List<int> ids)
{
try
{
//load from db...
}
catch (Exception e)
{
return HandleException<MyType>(e);
//returns MyTypeCollection with HasError set to TRUE and defined ErrorMessage
}
}