Everything was fine on the development server, but after deployment, there is an ArgumentException: Value does not fall within the expected range. Unfortunately, there is no way to directly debug the damaged web part, so I only have some log information (for example, the exception message above and the code section shown below). Here is the code throwing the exception:
using (SPSite site = new SPSite("http://mysite")) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists.TryGetList("MySPList"); foreach (SPListItem item in list.Items) { if (item["Code"].ToString() == code) { if (item["Favorites"] != null) { if (item["Favorites"].ToString().Contains(web.CurrentUser.ID + ";#" + web.CurrentUser.Name)) { // first case simple code } else { // second case simple code } } else { // second case simple code } break; } } } }
source share