Click here to Skip to main content
11,716,938 members (87,890 online)
   

C#

 
AnswerRe: source code for navigation Pin
Dave Kreskowiak20-Feb-13 7:38
mvpDave Kreskowiak20-Feb-13 7:38 
GeneralRe: source code for navigation Pin
Jibesh20-Feb-13 8:32
memberJibesh20-Feb-13 8:32 
GeneralRe: source code for navigation Pin
Dave Kreskowiak20-Feb-13 11:24
mvpDave Kreskowiak20-Feb-13 11:24 
QuestionHow to Show GIF Image Transparent C# Pin
ishrar19-Feb-13 21:53
memberishrar19-Feb-13 21:53 
AnswerRe: How to Show GIF Image Transparent C# Pin
Alan Balkany20-Feb-13 8:28
memberAlan Balkany20-Feb-13 8:28 
QuestionInstall software and menus depending upon radion button selection option used in MSI Pin
sjs4u19-Feb-13 19:33
membersjs4u19-Feb-13 19:33 
AnswerRe: Install software and menus depending upon radion button selection option used in MSI Pin
Eddy Vluggen20-Feb-13 0:31
mvpEddy Vluggen20-Feb-13 0:31 
GeneralRe: Install software and menus depending upon radion button selection option used in MSI Pin
sjs4u20-Feb-13 18:12
membersjs4u20-Feb-13 18:12 
GeneralRe: Install software and menus depending upon radion button selection option used in MSI Pin
Eddy Vluggen21-Feb-13 7:06
mvpEddy Vluggen21-Feb-13 7:06 
Questionproject Pin
pramodrastogi9119-Feb-13 18:14
memberpramodrastogi9119-Feb-13 18:14 
AnswerRe: project Pin
Jibesh19-Feb-13 19:52
memberJibesh19-Feb-13 19:52 
AnswerRe: project Pin
Abhinav S19-Feb-13 22:25
mvpAbhinav S19-Feb-13 22:25 
AnswerRe: project Pin
Marcus Kramer20-Feb-13 3:17
mvpMarcus Kramer20-Feb-13 3:17 
QuestionBinary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization. Pin
kandel1519-Feb-13 14:25
memberkandel1519-Feb-13 14:25 
Hello everyone. I get this excepction "Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.". I am looking for solution about this exception 2 day's now with out success.I tried (i think) everthing D'Oh! | :doh: .
Please can someone take a look on code bellow? where is error?

Thank's.

private player ByteArrayToPlayer(byte[] temp)
        {
            try
            {
                MemoryStream objectStream = new MemoryStream(temp);
 
                IFormatter BinaryFormatter
                            = new BinaryFormatter();
 
                objectStream.Position =0;
              
                return (player)BinaryFormatter.Deserialize(objectStream);     <--- get exception
            }
            catch (Exception ex)
            {
                ;
            }
            return null;
 

        }
        private byte[] PlayerToByteArray(player o)
        {
            try
            {
                objectStream = new MemoryStream();
 
               IFormatter BinaryFormatter
                            = new BinaryFormatter();
                
                BinaryFormatter.Serialize(objectStream, o);
                objectStream.Seek(0, SeekOrigin.Begin);
                return objectStream.ToArray();
            }
            catch (Exception ex)
            {
                ;
 
            }
 
            return null;
        }
 
Here are classes which serialize and deserialize.
 
[Serializable()]
        public class player :ISerializable
       {
           public byte[] temp;
           public int id;
           public bool isConnected;
           public cube[] receivedCubes;
           public cube[] cubesToSend;
           public string name;
           public bool isLoaded = false;
           public List<index>[] indexes;         // list of field indexes

           public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
           {
               info.AddValue("receivedCubes", receivedCubes);
               info.AddValue("name", name);
               info.AddValue("temp", temp);
               info.AddValue("isConnected", isConnected);
               info.AddValue("isLoaded", isLoaded);
               info.AddValue("cubesToSend", cubesToSend);
               info.AddValue("indexes", indexes);
               info.AddValue("id", id);
               
           }
           public player()
           { }
 
           public player(SerializationInfo info, StreamingContext ctxt)
           {
               receivedCubes = (cube[])info.GetValue("receivedCubes", typeof(cube[]));
               name = (String)info.GetValue("name", typeof(string));
               temp = (byte[])info.GetValue("temp", typeof(byte[]));
               isConnected = (bool)info.GetValue("isConnected", typeof(bool));
               isLoaded = (bool)info.GetValue("isLoaded", typeof(bool));
               cubesToSend = (cube[])info.GetValue("cubesToSend", typeof(cube[]));
               indexes = (List<index>[])info.GetValue("indexes", typeof(List<index>[]));
               id = (int)info.GetValue("id", typeof(int));
 
           }
 

 
       }
 
 [Serializable()]
        public class index   //object idex indicate where cube entry on the screen from other player
        {
            public int x;       
            public int y;
            public int indexOfTargetCube;     // that mark own of index( cube)
            public byte direct;
            public index()
            {
            }
 
              public index (SerializationInfo info, StreamingContext ctxt)
           {
 
               x = (int)info.GetValue("x", typeof(int));
               y = (int)info.GetValue("y", typeof(int));
               indexOfTargetCube = (int)info.GetValue("temp", typeof(int));
               direct=(byte)info.GetValue("isConnected",typeof(byte));
              
           
           }
              public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
            {
                info.AddValue("x", x);
                info.AddValue("y", y);
                info.AddValue("indexOfTargetCube", indexOfTargetCube);
                info.AddValue("direct", direct);
               
 
            }
 
        }
 

 [Serializable()]
    public class cube :ISerializable
    {
        public int x;  // position x
        public int y;   // position y
        public int size;  // size of cube
        public byte direct=2;  // direct , default is rigtUp=2;
        public  byte speed;    // speed cube
        public bool live;      // isLive ???
        public int room = 0;   // where cube is
        public bool isOut;     // idicate for dealer, that is cube out from players
        public bool isMarked = false; // indicate that cube have index
        public byte numOfExit = 0;    // num. of exit for dealer
        public int exploseTimer = 0;   // timer for explose
        public byte sizeTimer;          // timer for size cube
        public byte speedTimer=0;      // timer for speed cube
        public byte stopTimer=0;      // timer for stop cube
        public byte lastDirect=0;      // last direct, if cube keep position
        public int assumeX = 0;        // for index calculate
        public int assumeY=0;          // for index calculate

public cube()
        {
 
        }
 
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("x", x);
            info.AddValue("y", y);
            info.AddValue("size", size);
            info.AddValue("direct", direct);
            info.AddValue("speed", speed);
            info.AddValue("live", live);
            info.AddValue("room", room);
            info.AddValue("isOut", isOut);
            info.AddValue("isMarked", isMarked);
            info.AddValue("numOfExit", numOfExit);
            info.AddValue("exploseTimer", exploseTimer);
            info.AddValue("sizeTimer", sizeTimer);
            info.AddValue("speedTimer", speedTimer);
            info.AddValue("stopTimer", stopTimer);
            info.AddValue("lastDirect", lastDirect);
            info.AddValue("assumeY", assumeY);
            info.AddValue("assumeY", assumeY);
 
        }
 

public cube(SerializationInfo info, StreamingContext ctxt)
           {
               x=(int)info.GetValue("x", typeof(int));
               y=(int)info.GetValue("y", typeof(int));
               size=(int)info.GetValue("size", typeof(int));
               direct=(byte)info.GetValue("direct",typeof(byte));
               speed=(byte)info.GetValue("speed", typeof(byte));
               live=(bool)info.GetValue("live", typeof(bool));
               room=(int)info.GetValue("room", typeof(int));
               isOut=(bool)info.GetValue("isOut", typeof(bool));
               isMarked=(bool)info.GetValue("isMarked",typeof(bool));
               numOfExit=(byte)info.GetValue("numOfExit",typeof(byte));
               exploseTimer=(int)info.GetValue("exploseTimer",typeof(int));
               sizeTimer=(byte)info.GetValue("sizeTimer",typeof(byte));
               speedTimer=(byte)info.GetValue("speedTimer",typeof(byte));
               stopTimer=(byte)info.GetValue("stopTimer",typeof(byte));
               lastDirect=(byte)info.GetValue("lastDirect",typeof(byte));
               assumeX=(int)info.GetValue("assumeY",typeof(int));
               assumeY=(int)info.GetValue("assumeY",typeof(int));
         
           }
}


private player ByteArrayToPlayer(byte[] temp)
{
try
{
MemoryStream objectStream = new MemoryStream(temp);

IFormatter BinaryFormatter
= new BinaryFormatter();

objectStream.Position =0;

return (player)BinaryFormatter.Deserialize(objectStream); <--- get exception
}
catch (Exception ex)
{
;
}
return null;


}
private byte[] PlayerToByteArray(player o)
{
try
{
objectStream = new MemoryStream();

IFormatter BinaryFormatter
= new BinaryFormatter();

BinaryFormatter.Serialize(objectStream, o);
objectStream.Seek(0, SeekOrigin.Begin);
return objectStream.ToArray();
}
catch (Exception ex)
{
;

}

return null;
}

Here are classes which serialize and deserialize.

[Serializable()]
public class player :ISerializable
{
public byte[] temp;
public int id;
public bool isConnected;
public cube[] receivedCubes;
public cube[] cubesToSend;
public string name;
public bool isLoaded = false;
public List[] indexes; // list of field indexes

public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("receivedCubes", receivedCubes);
info.AddValue("name", name);
info.AddValue("temp", temp);
info.AddValue("isConnected", isConnected);
info.AddValue("isLoaded", isLoaded);
info.AddValue("cubesToSend", cubesToSend);
info.AddValue("indexes", indexes);
info.AddValue("id", id);

}
public player()
{ }

public player(SerializationInfo info, StreamingContext ctxt)
{
receivedCubes = (cube[])info.GetValue("receivedCubes", typeof(cube[]));
name = (String)info.GetValue("name", typeof(string));
temp = (byte[])info.GetValue("temp", typeof(byte[]));
isConnected = (bool)info.GetValue("isConnected", typeof(bool));
isLoaded = (bool)info.GetValue("isLoaded", typeof(bool));
cubesToSend = (cube[])info.GetValue("cubesToSend", typeof(cube[]));
indexes = (List[])info.GetValue("indexes", typeof(List[]));
id = (int)info.GetValue("id", typeof(int));

}



}

[Serializable()]
public class index //object idex indicate where cube entry on the screen from other player
{
public int x;
public int y;
public int indexOfTargetCube; // that mark own of index( cube)
public byte direct;
public index()
{
}

public index (SerializationInfo info, StreamingContext ctxt)
{

x = (int)info.GetValue("x", typeof(int));
y = (int)info.GetValue("y", typeof(int));
indexOfTargetCube = (int)info.GetValue("temp", typeof(int));
direct=(byte)info.GetValue("isConnected",typeof(byte));


}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("x", x);
info.AddValue("y", y);
info.AddValue("indexOfTargetCube", indexOfTargetCube);
info.AddValue("direct", direct);


}

}


[Serializable()]
public class cube :ISerializable
{
public int x; // position x
public int y; // position y
public int size; // size of cube
public byte direct=2; // direct , default is rigtUp=2;
public byte speed; // speed cube
public bool live; // isLive ???
public int room = 0; // where cube is
public bool isOut; // idicate for dealer, that is cube out from players
public bool isMarked = false; // indicate that cube have index
public byte numOfExit = 0; // num. of exit for dealer
public int exploseTimer = 0; // timer for explose
public byte sizeTimer; // timer for size cube
public byte speedTimer=0; // timer for speed cube
public byte stopTimer=0; // timer for stop cube
public byte lastDirect=0; // last direct, if cube keep position
public int assumeX = 0; // for index calculate
public int assumeY=0; // for index calculate

public cube()
{

}

public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("x", x);
info.AddValue("y", y);
info.AddValue("size", size);
info.AddValue("direct", direct);
info.AddValue("speed", speed);
info.AddValue("live", live);
info.AddValue("room", room);
info.AddValue("isOut", isOut);
info.AddValue("isMarked", isMarked);
info.AddValue("numOfExit", numOfExit);
info.AddValue("exploseTimer", exploseTimer);
info.AddValue("sizeTimer", sizeTimer);
info.AddValue("speedTimer", speedTimer);
info.AddValue("stopTimer", stopTimer);
info.AddValue("lastDirect", lastDirect);
info.AddValue("assumeY", assumeY);
info.AddValue("assumeY", assumeY);

}


public cube(SerializationInfo info, StreamingContext ctxt)
{
x=(int)info.GetValue("x", typeof(int));
y=(int)info.GetValue("y", typeof(int));
size=(int)info.GetValue("size", typeof(int));
direct=(byte)info.GetValue("direct", typeof(byte));
speed=(byte)info.GetValue("speed", typeof(byte));
live=(bool)info.GetValue("live", typeof(bool));
room=(int)info.GetValue("room", typeof(int));
isOut=(bool)info.GetValue("isOut", typeof(bool));
isMarked=(bool)info.GetValue("isMarked", typeof(bool));
numOfExit=(byte)info.GetValue("numOfExit", typeof(byte));
exploseTimer=(int)info.GetValue("exploseTimer", typeof(int));
sizeTimer=(byte)info.GetValue("sizeTimer", typeof(byte));
speedTimer=(byte)info.GetValue("speedTimer", typeof(byte));
stopTimer=(byte)info.GetValue("stopTimer", typeof(byte));
lastDirect=(byte)info.GetValue("lastDirect", typeof(byte));
assumeX=(int)info.GetValue("assumeY", typeof(int));
assumeY=(int)info.GetValue("assumeY", typeof(int));

}
}

AnswerRe: Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization. Pin
BobJanova20-Feb-13 0:04
memberBobJanova20-Feb-13 0:04 
AnswerRe: Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization. Pin
Pete O'Hanlon20-Feb-13 0:11
protectorPete O'Hanlon20-Feb-13 0:11 
QuestionWindows Mobile Pin
aymen amri19-Feb-13 5:04
memberaymen amri19-Feb-13 5:04 
AnswerRe: Windows Mobile Pin
Abhinav S19-Feb-13 5:49
mvpAbhinav S19-Feb-13 5:49 
GeneralRe: Windows Mobile Pin
aymen amri19-Feb-13 22:44
memberaymen amri19-Feb-13 22:44 
AnswerRe: Windows Mobile Pin
Pete O'Hanlon19-Feb-13 6:00
protectorPete O'Hanlon19-Feb-13 6:00 
GeneralRe: Windows Mobile Pin
aymen amri19-Feb-13 22:42
memberaymen amri19-Feb-13 22:42 
AnswerRe: Windows Mobile Pin
Pete O'Hanlon20-Feb-13 2:12
protectorPete O'Hanlon20-Feb-13 2:12 
QuestionHow to create dynamic menu Pin
ebrahim kalteh19-Feb-13 1:36
memberebrahim kalteh19-Feb-13 1:36 
AnswerRe: How to create dynamic menu Pin
BobJanova19-Feb-13 3:06
memberBobJanova19-Feb-13 3:06 
GeneralRe: How to create dynamic menu Pin
ebrahim kalteh19-Feb-13 8:13
memberebrahim kalteh19-Feb-13 8:13 
GeneralRe: How to create dynamic menu Pin
Jibesh19-Feb-13 8:58
memberJibesh19-Feb-13 8:58 
QuestionCLOSING FORMS Pin
airmigjr19-Feb-13 0:29
memberairmigjr19-Feb-13 0:29 
AnswerRe: CLOSING FORMS Pin
N a v a n e e t h19-Feb-13 1:05
memberN a v a n e e t h19-Feb-13 1:05 
AnswerRe: CLOSING FORMS Pin
V.19-Feb-13 1:23
memberV.19-Feb-13 1:23 
GeneralRe: CLOSING FORMS Pin
Jegan Thiyagesan19-Feb-13 3:26
memberJegan Thiyagesan19-Feb-13 3:26 
AnswerRe: CLOSING FORMS Pin
Dave Kreskowiak19-Feb-13 2:11
mvpDave Kreskowiak19-Feb-13 2:11 
GeneralRe: CLOSING FORMS Pin
airmigjr19-Feb-13 3:25
memberairmigjr19-Feb-13 3:25 
GeneralRe: CLOSING FORMS Pin
Dave Kreskowiak19-Feb-13 10:25
mvpDave Kreskowiak19-Feb-13 10:25 
AnswerRe: CLOSING FORMS Pin
BobJanova19-Feb-13 3:03
memberBobJanova19-Feb-13 3:03 
AnswerRe: CLOSING FORMS Pin
Shameel20-Feb-13 4:47
memberShameel20-Feb-13 4:47 
QuestionSetup Package for C# Windows application Pin
zead18-Feb-13 23:02
memberzead18-Feb-13 23:02 
AnswerRe: Setup Package for C# Windows application Pin
N a v a n e e t h19-Feb-13 1:08
memberN a v a n e e t h19-Feb-13 1:08 
Questionc# 64 bit .net c++ dll reference problem Pin
peter46218-Feb-13 22:54
memberpeter46218-Feb-13 22:54 
AnswerRe: c# 64 bit .net c++ dll reference problem Pin
N a v a n e e t h19-Feb-13 1:02
memberN a v a n e e t h19-Feb-13 1:02 
AnswerRe: c# 64 bit .net c++ dll reference problem Pin
Dave Kreskowiak19-Feb-13 2:16
mvpDave Kreskowiak19-Feb-13 2:16 
GeneralRe: c# 64 bit .net c++ dll reference problem Pin
harold aptroot19-Feb-13 3:19
memberharold aptroot19-Feb-13 3:19 
QuestionHow to read out whole static text present on external application's Input boxes or message boxes in C# Pin
sham bhand18-Feb-13 20:51
membersham bhand18-Feb-13 20:51 
AnswerRe: How to read out whole static text present on external application's Input boxes or message boxes in C# Pin
N a v a n e e t h18-Feb-13 22:27
memberN a v a n e e t h18-Feb-13 22:27 
AnswerRe: How to read out whole static text present on external application's Input boxes or message boxes in C# Pin
Gerry Schmitz19-Feb-13 20:27
memberGerry Schmitz19-Feb-13 20:27 
GeneralRe: How to read out whole static text present on external application's Input boxes or message boxes in C# Pin
sham bhand21-Feb-13 4:48
membersham bhand21-Feb-13 4:48 
GeneralRe: How to read out whole static text present on external application's Input boxes or message boxes in C# Pin
Gerry Schmitz21-Feb-13 8:40
memberGerry Schmitz21-Feb-13 8:40 
Question[SOLVED] Not Getting CPU Usage Pin
AmbiguousName18-Feb-13 18:51
memberAmbiguousName18-Feb-13 18:51 
QuestionC# run a process Pin
classy_dog18-Feb-13 7:02
memberclassy_dog18-Feb-13 7:02 
AnswerRe: C# run a process Pin
Eddy Vluggen18-Feb-13 7:48
mvpEddy Vluggen18-Feb-13 7:48 
GeneralRe: C# run a process Pin
classy_dog18-Feb-13 8:22
memberclassy_dog18-Feb-13 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 3 Sep 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid