On the development server everything was OK but after deployment there is an ArgumentException: Value does not fall within the expected range.
Unfortunately, there is no way to directly debug failing web part so i've got only some log information (e.g. exception message above and code section shown below).
Here is a 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;
}
}
}
}