c#


How to convert a 2D binary object in to a Dictonary<string, object> in C# using Binary Formatter


I want to convert an objeect of byte[][] type to Dictonary.
It always give an error "End of Stream encountered before parsing was completed."
Please help me .
public static object ByteToObjectArray(byte[][] ms)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream mStream = new MemoryStream();
mStream.Write(ms, 0, (int)ms.Length);
mStream.Position = 0;
return formatter.Deserialize(mStream) as object;
}
The HGETALL should return the data as
key1
data1
key2
data2
...
So interleaved... Now... Supposing the key is in UTF8:
public static Dictionary<string, object> ByteToObjectArray(byte[][] bytes)
{
var dict = new Dictionary<string, object>();
var formatter = new BinaryFormatter();
for (int i = 0; i < bytes.Length; i += 2)
{
string key = Encoding.UTF8.GetString(bytes[i]);
// Alternatively
//string key = Encoding.Unicode.GetString(bytes[i]);
using (var stream = new MemoryStream(bytes[i + 1]))
{
object obj = formatter.Deserialize(stream);
dict.Add(key, obj);
}
}
return dict;
}

Related Links

Making an array of textboxes is not working
Why converting int from SqlDataReader to long results in InvalidCastException?
Breeze executeQuery succeeds but returns empty objects
A socket operation was attempted to an unreachable host error
c# how to update particular fields
how to use Attribute.IsDefined in entity framework 5?
How do you get CSLA 3.02 BusinessListBase ListChanged event to identify the child object whose OnPropertyChanged triggered the event?
Design a combo box with disabled combo-box items [closed]
Reading a String as an int pointer
Web browser print from service running on windows 2012
How to publish Umbraco from Visual Studio without getting the install wizard
Should I use array or arraylist/list<>
How to access google analytics data without username/password
Changing signature appearance after signing pdf file with iTextSharp
C# Set ListView item selected after inserting a new Item in winform
c# treeview to xml error [duplicate]

Categories

HOME
classification
http
azure-documentdb
ide
ns2
ssh
pelican
azure-eventhub
highmaps
watson-iot
arguments
opengl-es
localhost
ms-access-2010
atlassian-fisheye
revit-api
phpexcel
fetch
velocity
adroitlogic
expo
mbed
logstash-configuration
bookmarklet
project-reactor
gpo
jq
fibonacci
inline-assembly
gsuite
scrapy-spider
priority-queue
deployment-descriptor
scalatest
knapsack-problem
adobe-captivate
dynamics-ax-2012-r3
recreate
overflow
availability
webmock
android-databinding
pygraphviz
word-wrap
directadmin
contenteditable
apiman
automapper-4
geminabox
stream-socket-client
evaluation
serialversionuid
beanshell
fckeditor
liferay-ide
senti-wordnet
iban
apache-commons-cli
sharing
spring-social-twitter
racket-student-languages
git-push
virtualenvwrapper
csc
hfp
weblogic-maven-plugin
web-optimization
jersey-test-framework
dday
overlapping
imageicon
maven-antrun-plugin
taverna
android-togglebutton
dnvm
consul-template
applinks
backtrace
indices
optimistic-locking
aiff
fedena
xmlserializer
zoneminder
nodeunit
db2-connect
xcode6.1-gm-seed
google-oauth-java-client
android-library
friendly-url
spawn
blotter
ncml
correctness
custom-cursor
optimistic-concurrency
motorola-droid
fileoutputstream
scriptmanager
peoplepicker
http-response-codes
activescaffold
mdd
pixel-bender
jettison
tracd

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App