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

using System;
using System.Runtime.Serialization;

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

    }
}

最佳答案

似乎您必须将“ 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"
        }
    }

10-07 14:57