exception
来源:互联网 发布:易语言ftp源码 编辑:程序博客网 时间:2024/04/26 04:49
Let me clarify this a bit....
This post is a bit old and I assumed it fell into some kind of a forum black hole. I've found out what the problem actually is. I ended up having to do a work-around, though.
The original error was Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''
this means that when the message was being deserialized, it was expecting an element instead of a string. For instance, instead of:
<hello><world>x</world></hello> it got something like <hello>world</hello> (the exception would occur when processing the hello element).
This was being caused by the fact that one of the members of serialized class was a byte array. Something along the lines of:
[DataContract()]class Person{ [DataMember()] public string Name{get;set;} [DataMember()] public byte[] Photo{get;set;} }
Now, here's the kicker....by default, when an array of some primitive type is serialized, you end up with child elements whose names are that type...it loooks like:
<Person> <Name>Amanda Reconwith</Name> <Photo> <byte>34</byte> <byte>34</byte> <byte>34</byte> <byte>34</byte> <byte>34</byte> <byte>34</byte> <byte>34</byte> <byte>34</byte> <byte>34</byte> <byte>34</byte> <byte>34</byte> </Photo></Person>
however, the serializer was smart and turned it into a Base64 encoded string
<Person> <Name>Chanda Leir</Name> <Photo>YTM0NZomIzI2OTsmIzM0NTueYQ==</Photo></Person>
So, the exception makes total sense. The de-serialization process is looking for a child element named 'byte' but encounters a string.
I appreciate that the serializer had the intelligence to do that, but its rather useless (dangerous) if the serializer is unable to de-serialize the message that it created (its looking for /Person/Photo/byte).
I ended up changing the data type to string and base64 encoded it myself.
Now, if anyone knows how to make a byte array, as a DataMember work, without the auto-magic encoding messing up, I would be very interested in hearing about that.
- Exception
- Exception
- Exception
- exception
- Exception
- Exception
- Exception
- exception
- Exception
- Exception
- Exception
- Exception
- exception
- exception
- exception
- Exception
- Exception
- Exception
- Windows对象、句柄与MFC对象
- RFID系统修改说明-090805
- 网关的作用
- symbian 下 不定参数的函数
- 福娃免费空间
- exception
- 开博客
- ProeWildfire 4.0破解、乱码、许可证问题的解决
- 正式开博啦^_^
- (转载)浅谈单元测试
- C语言专题——格式化I/O详解
- 开机自动运行的位置和木马运行方式
- 不绑定DataSet.Tables,而是一行一行的读取DataSet中的数据并填充到DataGridView中
- SQL Server 调试存储过程等数据库对象