The following code is throwing an exception called "Object reference not set to an instance of an object." suggest required changes
public List<WorkspaceRootObject> wrObj=null;
public RootObject rtObj=new RootObject();
Hashtable ht = new Hashtable();
Dictionary<int, Object> d = new Dictionary<int, Object>();
string contextUrl = txtRegServerLocation.Text + "/servlet/rest/v1/contexts";
Console.WriteLine("Url is:\n" + contextUrl);
HttpWebRequest contextReq = (HttpWebRequest)WebRequest.Create(contextUrl);
NetworkCredential ncr = new NetworkCredential("testuser1", "testuser1");
CredentialCache creCache = new CredentialCache();
creCache.Add(new Uri(contextUrl), "Basic", ncr);
contextReq.Credentials = creCache;
HttpWebResponse contextRes = (HttpWebResponse)contextReq.GetResponse();
Stream str = contextRes.GetResponseStream();
StreamReader strReader = new StreamReader(str);
string finalContextRes = strReader.ReadToEnd();
Console.WriteLine("response is...\n" + finalContextRes);
//Deserialzing Json
rtObj = JsonConvert.DeserializeObject<RootObject>(finalContextRes);
foreach (Item i in rtObj.items)
{
// Console.WriteLine("{0}",i.id);
string curId = i.id;
showWorkSpace(curId);
}
insertRecordInTable();
//DataGridViewRow row = new DataGridViewRow();
//erverDetails.Rows.Add(imageList1.Images[0], txtRegServerName.Text,txtRegServerLocation.Text);
}
else
{
MessageBox.Show("Invalid Url please provide full url");
}
}
catch (WebException ex)
{
using (Stream stream = (Stream)ex.Response.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
Console.WriteLine(reader.ReadToEnd());
}
}
}
Catch block is throwing this exception System.NullReferenceException was unhandled ?