Buffer cannot be null. Parameter name: buffer

Jan 6, 2011 at 11:02 PM

We have been getting this exception for some time now.   Has anyone seen anything similar?

 

at System.IO.MemoryStream..ctor(Byte[] buffer, Boolean writable)

at System.IO.MemoryStream..ctor(Byte[] buffer)

 at SharedCache.WinServiceCommon.Formatters.Compression.CheckHeader(Byte[] value)

at SharedCache.WinServiceCommon.CacheUtil.Get(IndexusMessage msg)

at SharedCache.WinServiceCommon.Provider.Cache.IndexusSharedCacheProvider.Get[T](String key)

at PCTS.CacheProvider.SharedCache.SharedCacheProvider.CacheGet[T](String key)

Aug 16, 2011 at 10:35 AM

Yes, I do. And I have no idea about how to solve it :(

System.ArgumentNullException: Buffer cannot be null.
Parameter name: buffer
   at System.IO.MemoryStream..ctor(Byte[] buffer, Boolean writable)
   at System.IO.MemoryStream..ctor(Byte[] buffer)
   at SharedCache.WinServiceCommon.Formatters.Compression.CheckHeader(Byte[] value)
   at SharedCache.WinServiceCommon.CacheUtil.Get(IndexusMessage msg)
   at SharedCache.WinServiceCommon.Provider.Cache.IndexusSharedCacheProvider.Get[T](String key)
   at SharedCache.WinServiceCommon.Provider.Cache.IndexusSharedCacheProvider.Get(String key)

Coordinator
Dec 20, 2011 at 8:04 AM
Edited Dec 21, 2011 at 7:36 AM

This is a bug.

There is a method: Formatters.Serialization.BinaryDeSerialize<T>(byte[] serializedObject), it changes byte[] to T.

When we get nothing from the cache, the method  will get null and can not change it to T, so we get the error.

We can modify the method by add follow codes at the starting line:

if (serializedObject == null) return default(T);

Or we can ensure the msg.Payload is not null before BinaryDeSerialize. For example:

In  IndexusSharedCacheProvider.cs there is a method: RegexGet(string regularExpression),

we can change if(CacheUtil.Get(msg)) to if(CacheUtil.Get(msg) && msg.Payload != null).

You can have a try.