0
.NET 멤버 자격 공급자를 사용하여 프로필 공급자를 사용하는 각 사용자의 데이터를 검색하는 메서드가 있습니다. 내가 방법이 메서드는 인덱스가 배열 경계 외부에있는 이유는 무엇입니까?
을 말한다 내 응용 프로그램의 로그에 오류를
GetUsers():
얻을 그러나 인덱스 배열의 범위를 벗어난 것입니다.
"내 메소드 GetUsers()
"이 내 로깅 메커니즘에 의해 추가되었습니다. 나머지는 .NET입니다.
protected Dictionary<string, string> Getusers()
{
try
{
Dictionary<string, string> userDictionary = new Dictionary<string, string>();
//Get string array of users in role from RoleProvider
var users = Roles.GetUsersInRole("MyRoleName");
//loop through the array of usernames
foreach (string user in users)
{
//Get user's first name and last name from the profile provider
ProfileCommon profile = (ProfileCommon)ProfileCommon.Create(user);
//add new key value pair with user name as the key and lastname,firstname as value
userDictionary.Add(user, string.Concat(profile.LastName + ",", profile.FirstName));
}
//sort the dictionary by the value not the key
//a little linq to do the sorting
var sortedDict = (from entry in userDictionary orderby entry.Value ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
return sortedDict;
}
catch (Exception ex)
{
LogController.LogError("In Method -- Getusers() --" + ex.Message);
//if error occurs return empty dictionary
return new Dictionary<string, string>();
}
}
어떤 줄이 그 예외를 정확하게 throw합니까? –
호출 스택을 던져서 오류가 실제로 생성되는 위치를 알 수 있습니다. ex.Message를 ex.ToString()으로 변경하고 살펴보십시오. – MNGwinn
실제로 예외를 기록해야하는 코드를 살펴보면'Roles.GetUsersInRole' 또는'ProfileCommon.CreateUser'에서 예외 자체가 발생할 수 있습니다. 즉, GetUsers 메소드가 호출하는 메소드 중 하나에서 발생합니다. 오류가있는 코드에서 실제 줄을 잡을 수 있도록 스택 추적 로깅을 추가합니다. –