Question

I tried to use this code in SCript#

Uri uri = new Uri(string.Format(string.Concat("http://localhost:49175/GetProjects")));
WebRequest request = WebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
request.ContentType = "application/json";
using (WebResponse response = request.GetResponse()) {
  using (var reader = new System.IO.StreamReader(response.GetResponseStream())) {
    string tmp = reader.ReadToEnd();
    return JsonConvert.DeserializeObject<List<string>>(tmp);
  }
}

But I have this error:

Error 3 The assembly 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.dll' is not a valid script assembly.

Is it the way to use System.Net, System.IO.StreamReader and Newtonsoft.Json in Script#? If it is impossible, how can I change the code?

Was it helpful?

Solution

I resolved the problem in this way

string tfsIntegration = string.Format(string.Concat("http://localhost:49175"));

System.Net.XmlHttpRequest getProjectRequest = new System.Net.XmlHttpRequest();

getProjectRequest.Open("GET", tfsIntegration + "/GetProjects", false);
getProjectRequest.SetRequestHeader("Accept", "application/json");
getProjectRequest.SetRequestHeader("Content-Type", "application/json; charset=utf-8");
getProjectRequest.SetRequestHeader("X-HTTP-Method", "MERGE");            
getProjectRequest.Send(null);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top