我不斷收到上面的錯誤消息,即使我註釋了錯誤發生的行。任何想法可能會造成這種情況?我試着用測試值重寫行,但我仍然得到相同的錯誤。「長度不能小於零」。在一個空行
這在調試模式下很好地工作,它只在部署中出現。
原始代碼:
Line 21: string domain, username;
Line 22: string text = Page.User.Identity.Name;
Line 23:
Line 24: domain = text.Substring(0, text.IndexOf("\\"));
Line 25: username = text.Substring(text.IndexOf("\\") + 1, text.Length - text.IndexOf("\\") - 1);
Source File: F:\<file path>\Default.aspx.cs Line: 23
測試代碼(同樣的錯誤):
Line 21: string domain, username;
Line 22: //string text = "TEST"; // Page.User.Identity.Name;
Line 23: // this line is blank
Line 24: domain = "TEST"; //text.Substring(0, text.IndexOf("\\"));
Line 25: username = "TEST"; // text.Substring(text.IndexOf("\\") + 1,
Source File: F:\<file path>\Default.aspx.cs Line: 23
這裏的堆棧跟蹤,如果有幫助的所有:
[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +12681546
Insufficiencies._Default.Page_Load(Object sender, EventArgs e) in F:\<file path>\Default.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048
在接下來的幾行代碼中會發生什麼?我想這個錯誤是存在的(堆棧跟蹤中的行號有時會有點混亂)。 – 2011-04-12 10:20:50
在此之前,只有一些變量的初始化和''using'標記的集合,根本沒有函數調用。 – Lyise 2011-04-12 10:55:09