Если вы столкнулись с ошибкой
и не знаете как справится для начала отправляемся в файл с ошибкой и заменяем эту часть кода
НА ЭТУ
Код:
"System.InvalidCastException: Object cannot be cast from DBNull to other types. at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) at System.Convert.ToInt32(Object value) at NeptuneEvrganizations.Manager.onResourceStart() in C:\Server\dotnet\resources\NeptuneEvo\Organizations\Manager.cs:line 430"
C#:
var memberOrganizationData = new OrganizationMemberData
{
UUID = Convert.ToInt32(Row["uuid"]),
Name = Row["name"].ToString(),
Id = orgId,
Rank = Convert.ToByte(Row["rank"]),
Date = Convert.ToDateTime(Row["date"]),
LastLoginDate = Convert.ToDateTime(Row["lastLoginDate"]),
Avatar = Row["avatar"].ToString(),
DepartmentId = Convert.ToInt32(Row["departmentId"]),
DepartmentRank = Convert.ToInt32(Row["departmentRank"]),
Score = Convert.ToInt32(Row["score"]),
Access = JsonConvert.DeserializeObject<List<RankToAccess>>(Row["access"].ToString()),
Lock = JsonConvert.DeserializeObject<List<RankToAccess>>(Row["lock"].ToString()),
};
НА ЭТУ
C#:
var memberOrganizationData = new OrganizationMemberData
{
UUID = Row["uuid"] != DBNull.Value ? Convert.ToInt32(Row["uuid"]) : 0,
Name = Row["name"] != DBNull.Value ? Row["name"].ToString() : string.Empty,
Id = orgId,
Rank = Row["rank"] != DBNull.Value ? Convert.ToByte(Row["rank"]) : (byte)0,
Date = Row["date"] != DBNull.Value ? Convert.ToDateTime(Row["date"]) : DateTime.MinValue,
LastLoginDate = Row["lastLoginDate"] != DBNull.Value ? Convert.ToDateTime(Row["lastLoginDate"]) : DateTime.MinValue,
Avatar = Row["avatar"] != DBNull.Value ? Row["avatar"].ToString() : string.Empty,
DepartmentId = Row["departmentId"] != DBNull.Value ? Convert.ToInt32(Row["departmentId"]) : 0,
DepartmentRank = Row["departmentRank"] != DBNull.Value ? Convert.ToInt32(Row["departmentRank"]) : 0,
Score = Row["score"] != DBNull.Value ? Convert.ToInt32(Row["score"]) : 0,
Access = Row["access"] != DBNull.Value ? JsonConvert.DeserializeObject<List<RankToAccess>>(Row["access"].ToString()) : new List<RankToAccess>(),
Lock = Row["lock"] != DBNull.Value ? JsonConvert.DeserializeObject<List<RankToAccess>>(Row["lock"].ToString()) : new List<RankToAccess>(),
};
Последнее редактирование модератором: