-1
Friends I’m coming in php and starting developing in C#. The differences are many the ideas I have, when I apply they give errors, as the problem I have a combobox html that filled dynamically with database data, that I thought separates the code that would be the value of the combobox and put as a value in each position of an array up to ae all right but does not work. The current version of the following error, does anyone have any idea how to fix?
Of that mistake:
"Undefined object reference for an object instance."
Code;
using System;
using System.Configuration;
using System.Data;
using System.Net.Http;
using System.Text;
using System.Web;
using Newtonsoft.Json.Linq;
namespace empresa.UI.ProcessEmpresa
{
/// <summary>
/// Summary description for AjaxPrazoMedioCliente
/// </summary>
public class AjaxPrazoMedioCliente : IHttpHandler
{
string[] v;//CRIACAO DO VETOR
public int i, j = 0;
public void ProcessRequest(HttpContext context)
{
Grupo = Convert.ToString(context.Request.QueryString["codgrupo"]);
temmontante = Convert.ToString(context.Request.QueryString["temmontante"]);
selecionado = Convert.ToString(context.Request.QueryString["selecionado"]);
temmontante = temmontante.Equals("") ? "0" : temmontante;
HttpClient client = null;
string retorno = string.Empty;
if (client == null)
{
client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["url_servidor"]);
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage resultado = client.GetAsync("xyz/Venda/PrazoMedio/" + Grupo + "/" + temmontante).Result;
retorno = resultado.Content.ReadAsStringAsync().Result;
if (resultado.StatusCode != System.Net.HttpStatusCode.NotFound)
{
if (retorno != "[]")
{
sb.Append("<select name=\"txtpagpedido\" id=\"txtpagpedido\" onchange=\"HabilitarDescontoPromocional()\" style=\"width: 200px;\" >");
sb.Append("<option value=\"0\">Selecione..</option>");
JArray usuarioarrray = JArray.Parse(retorno);
foreach (JObject obj in usuarioarrray.Children<JObject>())
{
foreach (JProperty prop in obj.Properties())
{
if (v[i] != null)//MEU TRECHO PESQUISEI QUE TALVEZ SOLUCIONARIA O ERRO
if (Convert.ToString(prop.Value) != v[i])
v[i] = prop.Value.ToString();
else
break;
//vetor[i] = Convert.ToString(prop.Value.ToString());
switch (prop.Name)
{
case "e4_CODIGO":
if (prop.Value.ToString().Equals(selecionado))
sb.Append("<option value=\"" + Convert.ToString(prop.Value.ToString()) + "\" selected=\"selected\" >");
else
sb.Append("<option value=\"" + Convert.ToString(prop.Value.ToString()) + "\" >");
break;
case "e4_DESCRI":
sb.Append(Convert.ToString(prop.Value.ToString()) + "</option>");
break;
default:
break;
}
i++;
}
}
sb.Append("</select>");
}
}
context.Response.Write(sb.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
error line??
– Francisco
If you had the line of error, it would be much easier to identify... But just out of curiosity, this "result" object is coming from where?
– Márcio Cristian
Hi friends thanks, for the return, come on, the staff was closing the company, I took the line because I had company reference, now I edited and put the full code and edited, now da para ter ideia, but the such return/ result is a json with the data, from the base, which fills the combobox. The error of when debugging it reaches the vector line
– hyperpixel
An Exception of type 'System.Nullreferenceexception' occurred in Xyz.UI.dll but was not handled in user code Additional information: Undefined object reference for an instance of an object. 

 em xyz.UI.Processxyz.Venda.AjaxPrazoMedioClienteEditar.ProcessRequest(HttpContext context)
 em System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
 em System.Web.HttpApplication.ExecuteStep(Iexecutionstep step, Boolean& completedSynchronously)
– hyperpixel