【问题标题】:Error The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8' while executing webapi错误“ObjectContent`1”类型无法序列化内容类型“application/xml;”的响应正文; charset=utf-8' 执行 webapi 时
【发布时间】:2017-12-13 09:34:41
【问题描述】:

执行以下 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.GetAllMovies();
    return Ok(movies);
}

业务逻辑方法

public List<Movie> GetAllMovies()
        {
            var movies = _movieRepository.GetMovies();
            _unitOfWork.Dispose();
            return movies;
        }

数据访问方式

public List<Movie> GetMovies()
        {
            var query = "dbo.spGetMovies";
            var list = SqlMapper.Query<Movie>(_unitOfWork.GetConnection(), query, commandType: CommandType.StoredProcedure);
            return list;

        }

【问题讨论】:

  • 是否存在内部异常,提供有关对象序列化失败原因的更多详细信息?
  • 将内容复制到流时出错。

标签: asp.net-web-api


【解决方案1】:

问题已解决。原因是 DTO 项目中的程序集有一个过时的 Newtonsoft.json dll。更新 DLL 对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 2012-12-07
    • 2013-10-01
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    相关资源
    最近更新 更多