meetsys
asked on
C# ->> Memcache and deserialisation
Hi,
I have a little C# application that successfully collects a value from memcache, it then attemptss to deserialise what I have using a memoryStream and BinaryFormatter.
Here is the code...
I can get at the data and retrieve it. I just cant deserialise it into an object. The follow line gives me a SerialisationException was unhandled runtime.
It states the following.
End of Stream encountered before parsing was completed.
I was wondering if anyone can help me to resolve this and prevent this runtime error or at least handle it.
Thank you.
Regards,
I have a little C# application that successfully collects a value from memcache, it then attemptss to deserialise what I have using a memoryStream and BinaryFormatter.
Here is the code...
using (MemcachedClient writeClient = new MemcachedClient())
{
string frObj= writeClient.Get<string>("myser");
byte[] byteArray = Encoding.ASCII.GetBytes(frObj);
MemoryStream stream = new MemoryStream(byteArray);
stream.Position = 0;
BinaryFormatter bf = new BinaryFormatter();
object d = bf.Deserialize(stream);
}
I can get at the data and retrieve it. I just cant deserialise it into an object. The follow line gives me a SerialisationException was unhandled runtime.
object d = bf.Deserialize(stream);
It states the following.
End of Stream encountered before parsing was completed.
I was wondering if anyone can help me to resolve this and prevent this runtime error or at least handle it.
Thank you.
Regards,
ASKER
That just gives off more runtime errors.
I get this one...
cannot convert from 'byte[]' to 'System.IO.Stream'
and an invalid arguments. This site is great. I never know about it before. Any ideas where I am going wrong.
I get this one...
cannot convert from 'byte[]' to 'System.IO.Stream'
and an invalid arguments. This site is great. I never know about it before. Any ideas where I am going wrong.
What does your serialization code look like?
ASKER
The serialisation code is a string of data that comes from another program. In fact it is actually serialised in .php and then passed to the 3rd party memcache and then picked up in c#. I'm just trying to deserialise it, not worried if it comes out wrong. Even if its not the same as how it went in. Just want to have something output.
If we're talking about the same PHP code that you demonstrated in your previous question, then I don't see where there is any serialization going on. Even if there were, you are talking about serialization/deserializat ion between two different programming languages. If you truly are serializing in your PHP code, then you need to use a form of serialization that is more cross-platform, like XML or JSON.
ASKER
Sure I get it. But it should still do something. Some sort of process that doesn't involve the runtime error I was enquiring about. Thats all I am looking to resolve at present.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all your advise kaufmed. Really appreciate it. Tricky business, some of this serialisation, memcache stuff. Thanks
Open in new window