[DataContract] 的命名空间 [英] Namespace for [DataContract]

查看:20
本文介绍了[DataContract] 的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到用于 [DataContract][DataMember] 元素的命名空间.根据我的发现,添加以下内容似乎就足够了,但在我的情况下还不够.

I can't find the namespace to use for [DataContract] and [DataMember] elements. According to what I've found, it seems that adding the following should be enough, but in my case it is not.

using System;
using System.Runtime.Serialization;

这是我的代码片段:

using System;
using System.Runtime.Serialization;

namespace MyNamespace {

    [DataContract]
    public class Tuple<T1, T2> {
            // A custom implementation of a Tuple
            //...
            //...
        }
}

我得到的错误:

找不到类型或命名空间名称DataContract"(您是否缺少 using 指令或程序集引用?)

The type or namespace name 'DataContract' could not be found (are you missing a using directive or an assembly reference?)

我是否使用了正确的命名空间?

Am I not using the right namespaces?

推荐答案

DataContractAttribute 类位于 System.Runtime.Serialization 命名空间中.

DataContractAttribute Class is in the System.Runtime.Serialization namespace.

您应该添加对 System.Runtime.Serialization.dll 的引用.尽管默认情况下不引用该程序集.要添加对项目的引用,您必须在解决方案资源管理器中转到引用 -> 添加引用并手动添加程序集引用.

You should add a reference to System.Runtime.Serialization.dll. That assembly isn't referenced by default though. To add the reference to your project you have to go to References -> Add Reference in the Solution Explorer and add an assembly reference manually.

这篇关于[DataContract] 的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆