其余异常:找不到用于类型 "myclass" 的构造函数。类应具有默认构造函数



我知道这个问题以前有人问过,但我找不到解决这个问题的答案。

我正在向返回 json 的 Web 服务发出请求,然后我使用 json.net 将该 json 保存为列表中的对象。

List<myclass> result;
var request = new RestRequest(url, Method.POST);
//Set the parameters of the request
//[...]
IRestResponse response = client.Execute(request)
Console.WriteLine(response.Content);
//response.Content = [{"nomPrecio":"string","nomPrecioEN":"string","IDrangoPrecio":0,"IDPoblacionMv":0,"NumOfertas":0,"NumOVotaciones":0,"Imagen":"anUrl"}]
//Everything works fine until here, and I can see the json is being received OK, but then...
result = JsonConvert.DeserializeObject<List<myclass>>(response.Content);

然后控制台显示以下消息:

Rest 异常:找不到用于 mynamespace.myclass 类型的构造函数。类应该有一个默认构造函数、一个带参数的构造函数或一个用 JsonConstructor 属性标记的构造函数。路径"[0].nomPrecio",第 1 行,位置 14。

namespace mynamespace
{
public class myclass
{
public myclass()
{
}
public myclass(string nomPrecio, string nomPrecioEN, int IDrangoPrecio, int IDPoblacionMv, int NumOfertas, int NumOVotaciones, string Imagen)
{
this.nomPrecio = nomPrecio;
this.nomPrecioEN = nomPrecioEN;
this.IDrangoPrecio = IDrangoPrecio;
this.IDPoblacionMv = IDPoblacionMv;
this.NumOfertas = NumOfertas;
this.NumOVotaciones = NumOVotaciones;
this.Imagen = Imagen;
}
public string nomPrecio { get; set; }
public string nomPrecioEN { get; set; }
public int IDrangoPrecio { get; set; }
public int IDPoblacionMv { get; set; }
public int NumOfertas { get; set; }
public int NumOVotaciones { get; set; }
public string Imagen { get; set; }
}
}

更奇怪的是,我对应用程序中的其他类进行了相同的操作,没有人返回此错误,所有这些都有效。

我尝试了很多像"json2csharp"这样的东西,但没有任何效果。

关于我可能做错了什么的任何提示?谢谢

一些链接器问题 mb?尝试为您的课程添加内容

[Preserve(AllMembers = true)] 

当链接器设置为"Sdk 和用户程序集"时,可能会发生这种情况

最新更新