Rally Rest .NET API throws KeyNotFoundException when posting a new defect without required field value
- by Triet Pham
I've tried to post a new defect to Rally via Rest .net api by the following code:
var api = new RallyRestApi("<myusername>", "<mypassword>", "https://community.rallydev.com");
var defect = new DynamicJsonObject();
defect["Name"] = "Sample Defect";
defect["Description"] = "Test posting defect without required field value";
defect["Project"] = "https://trial.rallydev.com/slm/webservice/1.29/project/5808130051.js";
defect["SubmittedBy"] = "https://trial.rallydev.com/slm/webservice/1.29/user/5797741589.js";
defect["ScheduleState"] = "In-Progress";
defect["State"] = "Open";
CreateResult creationResult = api.Create("defect", defect);
But the api throws a weird exception:
System.Collections.Generic.KeyNotFoundException was unhandled
Message=The given key was not present in the dictionary.
Source=mscorlib
StackTrace:
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Rally.RestApi.DynamicJsonObject.GetMember(String name)
at Rally.RestApi.DynamicJsonObject.TryGetMember(GetMemberBinder binder, Object& result)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at Rally.RestApi.RallyRestApi.Create(String type, DynamicJsonObject obj)
at RallyIntegrationSample.Program.Main(String[] args) in D:\Projects\qTrace\References\Samples\RallyIntegrationSample\Program.cs:line 24
The problem is when i checked out the trace log file of Rally, it showed exactly what wrong in the posting request:
Rally.RestApi Post Response:
{
"CreateResult":
{
"_rallyAPIMajor":"1",
"_rallyAPIMinor":"29",
"Errors":["Validation error: Defect.Severity should not be null"],
"Warnings":[]
}
}
Instead of given the proper CreateResult object with according errors information in its property, the Rally Rest .Net Api throws an unexpected exception.
Is that a mistake in Rally rest .net api or should i do any extra steps to get the CreatResult seamlessly in case of any errors returned by Rally service?
Many thanks for your helps.