请教:有谁遇到过这样的错误 Length cannot be less than zero

Liuyihannan 2011-03-05 04:39:57
页面上通过发送request给dll文件处理请求,出现下面的异常

Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Length cannot be less than zero.Parameter name: length] System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +10079752 Krystalware.HttpUploadManager.MultipartParser.ReadHeaders() in \operation_web\HttpUploadManager\MultipartParser.cs:130 KSystem.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171

在dll中有用到readheader方法,这个方法用问题吗?因为它的substring 看上去好像和出错信息相似
protected NameValueCollection ReadHeaders()
{
NameValueCollection headers = new NameValueCollection();

string line = ReadHeaderLine(_s);

// TODO: Handle continuations - lines starting with whitespace
while (line.Length > 0)
{
int pos = line.IndexOf(':');

headers[line.Substring(0, pos)] = line.Substring(pos + 1);

line = ReadHeaderLine(_s);
}

return headers;
}



...全文
3521 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
PitTroll 2011-03-07
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 liuyihannan 的回复:]
我补充下,如果真是因为“line中不包含:号”的情况,那为什么之前使用的时候都没有抛出异常呢,而突然就出现问题了
[/Quote]
这就是测试不充分造成的。
Liuyihannan 2011-03-07
  • 打赏
  • 举报
回复
我补充下,如果真是因为“line中不包含:号”的情况,那为什么之前使用的时候都没有抛出异常呢,而突然就出现问题了
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ivorstar 的回复:]

完全不知道你的string line = ReadHeaderLine(_s);是啥,估计line里没有:,pos=-1了
[/Quote]

嗯,刚看到。已经有了回复。
  • 打赏
  • 举报
回复
[Quote=引用楼主 liuyihannan 的回复:]
int pos = line.IndexOf(':');

headers[line.Substring(0, pos)] = line.Substring(pos + 1);
[/Quote]
显然,写这个程序的人没有测试过line中不包含:号的情况。
Liuyihannan 2011-03-05
  • 打赏
  • 举报
回复
我在网上查了下, 对于上传文件时ReadHeaders方法都是这么写的,难道没有错吗?
另外,这个网站在以前使用的时候都没错,这次突然才抛的异常,有没有人遇到累死的情况呢?
Code従業員 2011-03-05
  • 打赏
  • 举报
回复
Length cannot be less than zero 说明了问题

MessageBox.Show(line);//看看
wuyq11 2011-03-05
  • 打赏
  • 举报
回复
F11单步看看Substring中值不能小于0
ivorstar 2011-03-05
  • 打赏
  • 举报
回复
完全不知道你的string line = ReadHeaderLine(_s);是啥,估计line里没有:,pos=-1了

111,088

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧