Alachisoft / NCache

NCache: Highly Scalable Distributed Cache for .NET
http://www.alachisoft.com
Apache License 2.0
651 stars 124 forks source link

Write-Behind Provider #25

Open tnight opened 6 years ago

tnight commented 6 years ago

Hello,

I have been working with the open source NCache for about a week and so far I like it a lot! One of the features I want to use is the write-behind provider. I wrote a simple one to test with, but today I have run into a roadblock. The WriteOperation array that is passed to my WriteToDataSource method has a strange Value.

This code below prints System.Byte[] as the type of the cache value. Also, the bytes within the byte array look like they are my object as it would appear if serialized by the BinaryFormatter but deserializing fails with an error: Binary stream '0' does not contain a valid BinaryHeader.

All the examples I can find are showing that I can just cast the ProviderCacheItem.Value to the type of object I wrote into the cache. Here is one example: http://www.alachisoft.com/resources/docs/ncache/prog-guide/configure-write-through-provider.html

Thanks for any help that anyone can offer!

public OperationResult[] WriteToDataSource(WriteOperation[] operations)
{
    foreach (WriteOperation operation in operations)
    {
        object value = operation.ProviderCacheItem.Value;
        string valueTypeAsString = value.GetType().ToString();
        WriteToLogFile($"value object type: [{valueTypeAsString}]");
    }
}
Kal-Alachisoft commented 6 years ago

Hi @tnight ,

Are all the dependent assemblies of the write through provider you've configured placed in the "C:\Program Files\NCache\Deploy" folder? This includes any domain objects you've used in the Write through provider?