C# 设置属性时获取StackOverflowException
} 有人知道错误在哪里吗C# 设置属性时获取StackOverflowException,c#,wcf,properties,stack-overflow,C#,Wcf,Properties,Stack Overflow,} 有人知道错误在哪里吗 提前感谢。您可以通过再次调用属性设置器来设置属性值,而不是直接设置其支持字段。这会导致无限递归和堆栈溢出 [DataContract] public class Empleado { private int _idEmpleado; [DataMember(IsRequired = false)] public int idEmpleado { get { return _idEmplead
提前感谢。您可以通过再次调用属性设置器来设置属性值,而不是直接设置其支持字段。这会导致无限递归和堆栈溢出
[DataContract]
public class Empleado
{
private int _idEmpleado;
[DataMember(IsRequired = false)]
public int idEmpleado
{
get { return _idEmpleado; }
set { idEmpleado = value; } ERROR
}
private int _idUsuario;
[DataMember(IsRequired = false)]
public int idUsuario
{
get { return _idUsuario; }
set { idUsuario = value; }
}
private string _nombre;
[DataMember(IsRequired = false)]
public string nombre
{
get { return _nombre; }
set { nombre = value; }
}
private string _apellidos;
[DataMember(IsRequired = false)]
public string apellidos
{
get { return _apellidos; }
set { apellidos = value; }
}
private string _telefono1;
[DataMember(IsRequired = false)]
public string telefono1
{
get { return _telefono1; }
set { telefono1 = value; }
}
}
您可以通过再次调用属性设置器来设置属性值,而不是直接设置其支持字段。这会导致无限递归和堆栈溢出
[DataContract]
public class Empleado
{
private int _idEmpleado;
[DataMember(IsRequired = false)]
public int idEmpleado
{
get { return _idEmpleado; }
set { idEmpleado = value; } ERROR
}
private int _idUsuario;
[DataMember(IsRequired = false)]
public int idUsuario
{
get { return _idUsuario; }
set { idUsuario = value; }
}
private string _nombre;
[DataMember(IsRequired = false)]
public string nombre
{
get { return _nombre; }
set { nombre = value; }
}
private string _apellidos;
[DataMember(IsRequired = false)]
public string apellidos
{
get { return _apellidos; }
set { apellidos = value; }
}
private string _telefono1;
[DataMember(IsRequired = false)]
public string telefono1
{
get { return _telefono1; }
set { telefono1 = value; }
}
}
非常感谢你。编辑后,它返回以下错误:命名空间中的codeElement ListaDoClientResult不能将子内容反序列化为对象。请使用XmlNode[]反序列化此XML模式。code@Javiere:这是与序列化相关的问题。作为一个单独的问题发布,请提供更多细节,他们将是必要的。再次感谢你。好的,我会再写一篇文章。非常感谢。编辑后,它返回以下错误:命名空间中的codeElement ListaDoClientResult不能将子内容反序列化为对象。请使用XmlNode[]反序列化此XML模式。code@Javiere:这是与序列化相关的问题。作为一个单独的问题发布,请提供更多细节,他们将是必要的。再次感谢你。好的,我会再写一篇文章。
public int idEmpleado
{
get { return _idEmpleado; }
set { idEmpleado = value; } // SHOULD BE _idEmpleado = value
}