Question

I have a code snippet that was working until the end of last week sometime . It is simple enough, for a given project name , give me the team members associated with it . The query itself works and gives me a result set, but when I try and iterate over any of the dictionaries I get an exception .

Here is the snippet

            try
            {
                Request projectRequest = new Request("project");
                projectRequest.Fetch = new List<string>()
                                            {
                                                "Name",
                                                "Owner",
                                                "State",
                                                "Description",
                                                "Workspace",
                                                "TeamMembers",
                                                "Releases"};
                String projectName = rallyProject.Text;
                // get me results for the given project
                projectRequest.Query = new Query("Name", Query.Operator.Equals, projectName);
                QueryResult queryProjectResults = restApi.Query(projectRequest);
                DynamicJsonObject myProject = queryProjectResults.Results.First();

                myProjectReference = myProject["_ref"];

                var projectState = myProject["State"];
                var workspace = myProject["Workspace"];
                myWorkspaceRef = workspace["_ref"];
                string currentUser = userComboBox.Text;

                userComboBox.DataSource = null;
                userComboBox.Items.Clear();
                userComboBox.Sorted = false;

                // iterationComboBox.Items.Add("Unscheduled");
                userMap.Clear();
                List<string> userList = new List<string>();
                userList.Add("");

------- all works up till this point, the project query succeeds an I can extract simple strings. The next statement however fails, the first enumeration throws the exception.

                foreach (var result in myProject["TeamMembers"])
                {
                    userMap.Add(result["_refObjectName"], result["_ref"]);
                    userList.Add(result["_refObjectName"]); 
                }
                userList.Sort();
             }
            catch (Exception ex)
            {
                myWorkspaceRef = null;
            }

The exception thrown is Cannot implicitly convert type 'Rally.RestApi.DynamicJsonObject' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)

As mentioned , this has worked for months up until the last week or so .Only thing changed on the machine would be the normal windows updates .

Any advice would be most welcome, Thanks in advance

John

Was it helpful?

Solution

I can replicate the same error when using the latest dll from Rally REST .NET Toolkit's repo and v2.0 of WS API (which we encourage users to do, since 1.43 of WS API will not be supported after June of this year per this schedule).

To make your code work with v2.0 of WS API I modified your code slightly to make a separate call to get the objects of TeamMembers collection:

Request teamRequest = new Request(myProject["TeamMembers"]);
                QueryResult teamResult = restApi.Query(teamRequest);
                foreach (var teammate in teamResult.Results)
                {
                    userMap.Add(teammate["_refObjectName"], teammate["_ref"]);
                    userList.Add(teammate["_refObjectName"]);
                }

In v2.0 of Rally Web Services API we removed the ability to return child collections in the same response for performance reasons. In v2.0 fetching a collection will return an object with the count and the url from which to get the collection. In the older versions of WS API certain fetch lists create a lot recursive calls, and all the collections included in the fetch make the call quite expensive. In WS API v2.0 this will not happen, since a separate call will have to be made in order to get objects of the collections.

If you encountered this problem when running your code against WS API 1.43 or older, please try again since yesterday we had a temporarily issue that affected 1.43 when fetch included Releases. This issue was resolved the same day.

Here is a full code that works with v2.0 of WS API:

static void Main(string[] args)
            {
                RallyRestApi restApi;

                restApi = new RallyRestApi("user@co.com", "secret", "https://rally1.rallydev.com", "v2.0");
                String workspaceRef = "/workspace/12352608129";
                try
                {
                    Request projectRequest = new Request("project");
                    projectRequest.Fetch = new List<string>()
                                                {
                                                    "Name",
                                                    "Owner",
                                                    "State",
                                                    "Description",
                                                    "Workspace",
                                                    "TeamMembers",
                                                    "Releases"};
                    projectRequest.Workspace = workspaceRef;
                    String projectName = "Company X";

                    projectRequest.Query = new Query("Name", Query.Operator.Equals, projectName);
                    QueryResult queryProjectResults = restApi.Query(projectRequest);
                    DynamicJsonObject myProject = queryProjectResults.Results.First();

                    String myProjectReference = myProject["_ref"];

                    var projectState = myProject["State"];
                    List<string> userList = new List<string>();
                    userList.Add("");
                    Dictionary<string, string> userMap = new Dictionary<string, string>();

                    Request teamRequest = new Request(myProject["TeamMembers"]);
                    QueryResult teamResult = restApi.Query(teamRequest);
                    foreach (var teammate in teamResult.Results)
                    {
                        userMap.Add(teammate["_refObjectName"], teammate["_ref"]);
                        userList.Add(teammate["_refObjectName"]);
                    }
                    userList.Sort();
                    Console.WriteLine("Test user: " + userMap["nick01"]);

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);

                }
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top