8
I’m trying to Serialize a list of objects to Json and have received the following error:
An Exception of type
'System.Invalidoperationexception' occurred in Microsoft.Web.Extensions.dll but was not handled in user code Additional information: A circular Reference was Detected while serializing an Object of type 'System.Data.Entity.DynamicProxies.Pais_fe2360f9c3dd9892003fc5dc33ef9bd07698cff62033ee442867f74c88f09ac7'.
I’ve been using:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void GetListaPais(string prefixText, string contextKey)
{
    var serializer = new JavaScriptSerializer();
    var json = serializer.Serialize(AuxiliarControler.ListaPais(prefixText,contextKey));
    Context.Response.Clear();
    Context.Response.ContentType = "application/json";
    Context.Response.Flush();
    Context.Response.Write(json);
} 
Method obtaining the list of Pais:
public static List<Pais> ListaPais(string nomePais, int IDIdioma)
{
    using (entidadesIUS entidades = new entidadesIUS())
    {
        return entidades.Pais.Where(p => p.IDIdioma == IDIdioma && 
            p.Pais1.Contains(nomePais)).ToList();
    }
}
Entity Pais
public partial class Pais
{
    public Pais()
    {
        this.CAL = new HashSet<CAL>();
        this.Clientes = new HashSet<Clientes>();
    }
    public int IDPais { get; set; }
    public string Pais1 { get; set; }
    public int IDIdioma { get; set; }
    public virtual ICollection<CAL> CAL {get; set; }
    public virtual Idiomas Idiomas {get; set; } 
    public virtual ICollection<Clientes> Clientes {get; set; }
}
"Gives dick" is the most subjective comment possible. What is the mistake? What have you tried to do to Ana it?
– William Barbosa
What is the IDE you are using?
– Alex