简体   繁体   English

用户代码未处理参数 null 异常

[英]argument null exception was unhandled by user code

I am getting following error.我收到以下错误。

argument null exception was unhandled by user code.用户代码未处理参数 null 异常。 Value cannot be null.值不能是 null。 Parameter name: value参数名称:值

in the below code at Bold place.在下面粗体的代码中。

public static void InsertIntoCache(string cacheKey, object value)
{
    HttpRuntime.Cache.Insert(cacheKey, value, null, DateTime.Now.Add(new TimeSpan(0, CacheDuration, 0)), **Cache.NoSlidingExpiration**, CacheItemPriority.Default,null);
}

please help me on this.请帮助我。

The method signature for Cache.Insert() is (taken from MSDN ): Cache.Insert()的方法签名是(取自MSDN ):

public void Insert (
string key,
Object value,
CacheDependency dependencies,
DateTime absoluteExpiration,
TimeSpan slidingExpiration,
CacheItemPriority priority,
CacheItemRemovedCallback onRemoveCallback
)

The error is telling you that value , which is the 2nd parameter in the .Insert() method, can not be null.该错误告诉您value ,它是.Insert()方法中的第二个参数,不能是 null。 That means that your method is being called with null as the 2nd parameter, like:这意味着使用 null 作为第二个参数调用您的方法,例如:

InsertIntoCache("some_key", null);  // this will throw an exception.

Basically, you can not cache 'null' as a value.基本上,您不能将“null”缓存为值。 If you scroll down in this link to "Exceptions", it states that Insert() will throw a ArgumentNullException when:如果您在此链接中向下滚动到“异常”,则表明 Insert() 将在以下情况下抛出ArgumentNullException

The key or value parameter is a null reference键或值参数是 null 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM