它从小于 2k 的 .eml 文件读取。 你猜怎么了? msgCount是1717924456为什么ReadInt32返回这么大?
protected void Load( Stream msgStream )
{
if( msgStream == null )
throw new ArgumentNullException( "messageStream" );
BinaryReader bsr = new BinaryReader( msgStream );
MailAddress = bsr.ReadString();
MailUser = bsr.ReadString();
MailServer = bsr.ReadString();
UseSsl = bsr.ReadBoolean();
MailPort = bsr.ReadInt32();
MailPassword = bsr.ReadString();
int i, msgCount = bsr.ReadInt32();
for( i = 0; i < msgCount; i++ )
{
int msgLen = bsr.ReadInt32();
MessageExt msg = new MessageExt( bsr.ReadBytes( msgLen ) );
msg.RecvTime = DateTime.FromBinary( bsr.ReadInt64() );
这段代码以前可以工作,但现在看起来很奇怪,似乎我更改了一些导致此类异常的设置?
最佳答案
1717924456 == 0x66657268 看起来很像英文字符的 ASCII 十六进制代码。
假设是小端处理器,它对应于字符串“href”(0x68、0x72、0x65、0x66)。因此,您可能从错误的地址(即消息正文)阅读。
使用十六进制编辑器手动验证文件的内容并确保其未损坏。
关于BinaryReader ReadInt32() 返回的数字太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25736222/