Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:20:54+00:00 2026-06-11T11:20:54+00:00

Returning information from webservice. I have made a class for the return object. But

  • 0

Returning information from webservice. I have made a class for the return object. But I get the following error message when assigning results to each list item.

When invoking my webservice I am returned with the following message:

System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection. Parameter name:
index at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index) at
NewUser.ADMethods.GetUserInfo(String userName)

Please help!

public class UserInformation
{
    public string givenname { get; set; }
    public string surname { get; set; }            
}

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<UserInformation> GetUserInfo(string userName)
{
    // Gather User Info
    // Invoke Directory Searcher & Directory Entry
    DirectorySearcher ds = new DirectorySearcher();
    // Apply filter to search
    ds.Filter = "(&(objectCategory=user)(samaccountname=" + userName + "))";

        SearchResult sr = ds.FindOne();
        List<UserInformation> UserInfo = new List<UserInformation>();
        UserInfo[0].givenname = sr.Properties["givenname"].ToString();
        return UserInfo;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:20:55+00:00Added an answer on June 11, 2026 at 11:20 am

    Your problem is that you are creating a list, which is initially empty, and then trying to access value for a first item, which does not exist yet.

    You have to create the item and then add it to the list:

    List<UserInformation> UserInfo = new List<UserInformation>();
    UserInformation item = new UserInformation();
    item.givenname = sr.Properties["givenname"].ToString();
    UserInfo.Add(item);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method that is supposed to parse information from an XML
So I'm returning xml from a web service and I get this message in
I have several laptops in the field that need to daily get information from
SVN seems to have a very straightforward way to return information from a date
NSString is returning as NULL while Importing from ViewController Class were i want to
How can I pass custom error information from an ASP.NET MVC3 JsonResult method to
Alright so I'm using Microsoft's Web Services and AJAX to get information from a
I am reading information from a device and it's returning data to me in
Here is my basic situation. I'm trying to use NHibernate to get information from
I'm developing a script to grab some information from an external url. But I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.