我有以下代码尝试从 Web api 服务获取 Appication 对象。我得到以下异常:
InnerException = {“无法创建BusinessEntities.WEB.IApplicationField 类型的实例。类型是接口或抽象类,无法实例化。路径'_applicationFormsList[0]._listApplicationPage[0]._listField[0]._applicationFieldID',行1,位置 194。"}。
我不明白为什么将 FieldList 更改为 Interface 会导致反序列化对象出现问题。任何指针都非常感谢。
Task<HttpResponseMessage> task = HttpClientDI.GetAsync(someUri);
HttpResponseMessage response = task.Result;
HttpClientHelper.CheckResponseStatusCode(response);
try
{
Application application = response.Content.ReadAsAsync<ApplicationPage>().Result;
return application;
}
catch (Exception ex)
{
throw new ServiceMustReturnApplicationException(response);
}
[Serializable]
public class ApplicationPage
{
#region Properties
public int PageOrder { get; set; }
public string Title { get; set; }
public string HtmlPage { get; set; }
public int FormTypeLookupID { get; set; }
List<IApplicationField> _listField = new List<IApplicationField>();
public List<IApplicationField> FieldList
{
get { return _listField; }
set { _listField = value; }
}
}