Asp.net web api 将';ObjectContent`1';类型未能序列化内容类型';的响应正文;应用程序/xml;字符集=utf-8';在执行webapi时
我在执行以下web api方法时遇到运行时错误Asp.net web api 将';ObjectContent`1';类型未能序列化内容类型';的响应正文;应用程序/xml;字符集=utf-8';在执行webapi时,asp.net-web-api,Asp.net Web Api,我在执行以下web api方法时遇到运行时错误 The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'. web api控制器 [Route("api/movies")] public IHttpActionResult Get() { var movies = _movieBusiness.GetAllMovie
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
web api控制器
[Route("api/movies")]
public IHttpActionResult Get()
{
var movies = _movieBusiness.GetAllMovies();
return Ok(movies);
}
业务逻辑方法
public List<Movie> GetAllMovies()
{
var movies = _movieRepository.GetMovies();
_unitOfWork.Dispose();
return movies;
}
公共列表GetAllMovies()
{
var movies=_movieRepository.GetMovies();
_unitOfWork.Dispose();
返回电影;
}
数据存取方法
public List<Movie> GetMovies()
{
var query = "dbo.spGetMovies";
var list = SqlMapper.Query<Movie>(_unitOfWork.GetConnection(), query, commandType: CommandType.StoredProcedure);
return list;
}
public List GetMovies()
{
var query=“dbo.spGetMovies”;
var list=SqlMapper.Query(_unitOfWork.GetConnection(),Query,commandType:commandType.storedProcess);
退货清单;
}
问题已经解决。原因是DTO项目中的程序集具有过时的Newtonsoft.json dll。更新DLL对我有效。是否存在内部异常,其中包含有关对象序列化失败原因的详细信息?将内容复制到流时出错。