ASP.NET VNext类库System.Runtime.Serialization

时间:2015-01-26 16:01:19

标签: asp.net serialization datacontractserializer asp.net-core vs-2015-preview

尝试在ASP.NET vNext类库项目中创建可序列化的类。无法提供我的课程项目[DataContract]或[DataMember]属性。当我刚开始探索vNext时,我有点困惑。如果有人可以指导我是否正在做正确的事。我的小样本代码。

using System;
using System.Runtime.Serialization;

namespace Schlouds.Business.Entities
{
    [DataContract]
    public class Student
    {
        [DataMember]
        public Guid StudentId { get; set; }

    }
}

3 个答案:

答案 0 :(得分:7)

您似乎必须添加" System.Runtime.Serialization "到" frameworkAssemblies "。

参见project.json文件示例:

"net45": {
        "frameworkAssemblies": {
            "System.Runtime.Serialization": "4.0.0.0"
        },
        "dependencies": {
            "System.Reflection": "4.0.10-beta-22416",
            "System.Reflection.Extensions": "4.0.0-beta-22526",
            "System.Reflection.Primitives": "4.0.0-beta-22526",
            "System.Reflection.TypeExtensions": "4.0.0-beta-22526",
            "System.Collections": "4.0.10-beta-22526",
            "System.Collections.Specialized": "4.0.0-beta-22526",
            "System.Linq": "4.0.0-beta-22526",
            "System.Linq.Expressions": "4.0.0-beta-22526",
            "System.Linq.Queryable": "4.0.0-beta-22526",
            "System.Runtime": "4.0.20-beta-22526",
            "System.Runtime.Serialization.Primitives": "4.0.0-beta-22526",
            "System.Runtime.Serialization.Xml": "4.0.10-beta-22526",
            "System.Runtime.Serialization.Json": "4.0.0.0-beta-22526"
        }
    }

答案 1 :(得分:3)

这是将旧命名空间与新命名空间匹配的非官方API。

http://packagesearch.azurewebsites.net/

对于那些属性,如果使用核心,则需要System.Runtime.Serialization.Xml 4.0.10-beta-22416

答案 2 :(得分:0)

您可以使用Nuget for .net core中的 Microsoft.AspNetCore.Mvc.Formatters.Json (或 Microsoft.AspNetCore.Mvc.Formatters.Xml )程序包。< / p>