Fin de flujo encontrado antes de que el análisis se completó?


Estoy tratando de deserializar una secuencia pero siempre obtengo este error "Fin de la secuencia encontrada antes de que se completara el análisis"?

Aquí está el código:

        //Some code here
        BinaryFormatter b = new BinaryFormatter();
        return (myObject)b.Deserialize(s);//s---> is a Stream object that has been fill up with data some line over here

¿Alguien tiene ideas?

Author: Mister Dev, 2008-11-20

7 answers

Intente establecer la posición a 0 de su flujo y no use su objeto, sino el tipo de objeto.

        BinaryFormatter b = new BinaryFormatter();
        s.Position = 0;
        return (YourObjectType)b.Deserialize(s);
 48
Author: Patrick Desjardins,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-11-20 19:48:49

Asegúrese de que la serialización se ha completado, y que el tipo de serialización coincide con el tipo de serialización (es decir, asegúrese de serializar con un BinaryFormatter si está serializando con uno). Además, asegúrese de que el flujo que serializó realmente terminó de serializar, con un flujo.Flush () o algo en ese sentido.

 6
Author: GWLlosa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-11-20 20:00:30
s.Position = 0;

Esto se debe a que tiene que ir al inicio de nuevo para empezar a copiar datos en la matriz!

 1
Author: chandpriyankara,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-11 06:42:17

En mi caso usé:

stream.Seek(0, SeekOrigin.Begin);

Después de serializar la corriente, y antes de deserializar la corriente funciona encanto. espero que esto ayude!

 0
Author: Alia Ramli Ramli,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-29 15:51:20

Tuve la misma excepción lanzada, hasta que agregué la etiqueta [Serializable] a la clase que estaba Serializando:)

Entonces todo funcionó perfectamente.

 0
Author: Ryan O'Connor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-22 00:41:34

Compruebe que tiene

[Serializable]

Por encima de su clase

Así:

[Serializable]
Public void SomeClass{
}
 0
Author: dangalg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-19 06:55:12

Acabo de encontrar un error similar

Se trataba de obtener un tipo de datos diferente al serializar y deserializar. Por error, al almacenar los datos a mariadb usé MediumText y al obtener los datos usé Text, es por eso que solo obtuve una parte del flujo.

Simplemente compruebe si los tipos de datos son los mismos.

 0
Author: lastboy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-11 06:33:55