您的位置:首页 > 移动开发 > Objective-C

Error:You must write an attribute 'type'='object' after writing the attribute with local name '__type'

2012-05-16 14:13 513 查看
昨天在使用WebApi的时候,遇到这个错误。

You must write an attribute 'type'='object' after writing the attribute with local name '__type'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Xml.XmlException: You must write an attribute 'type'='object' after writing the attribute with local name '__type'.
代码如下:

public HttpResponseMessage<List<ArticleSimple>> GetArticles(DateTime date)
{
//DONE returns top 10 articles
ArticleService service = new ArticleService();

var articles = service.GetLatestArticleSimplesByDate(date, null);

//DONE using viewModel that do not display Metadata and some useless properties
return new HttpResponseMessage<List<ArticleSimple>>(articles, System.Net.HttpStatusCode.OK);
}


 

解决方法:

        有两种,其中一种简单的是在实例化DbContext时指定 context.Configuration.ProxyCreationEnabled = false;

参考:

       http://forums.asp.net/p/1773173/4848023.aspx/1?You+must+write+an+attribute+type+object+after+writing+the+attribute+with+local+name+__type+

       http://msdn.microsoft.com/zh-cn/library/bb738612
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐