为什么我不能引用System.ComponentModel.DataAnnotations? [英] Why can't I reference System.ComponentModel.DataAnnotations?

查看:5502
本文介绍了为什么我不能引用System.ComponentModel.DataAnnotations?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用DataAnnotations在我的WPF项目指定字符串的最大长度,具有以下内容:

I'm trying to use DataAnnotations in my WPF project to specify a maximum length of strings, with the following:

using System.ComponentModel.DataAnnotations;

不过,我得到的错误

However, I get the error

类型或命名空间名称'DataAnnotations不存在的
  命名空间System.ComponentModel(是否缺少程序集
  引用?)

The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?)

我见过其中 DataAnnotations 确实的存在于这个命名空间中的其他例子。我使用C#4。是否有任何理由为什么我不能用这个?我能做些什么来解决这个问题?

I've seen other examples where DataAnnotations does exist in this namespace. I'm using C#4. Is there any reason why I can't use this? What can I do to fix it?

推荐答案

您必须引用在此命名空间中定义的组件(它不是由默认在Visual Studio模板参考)。打开你的参考经理和添加到System.ComponentModel.DataAnnotations集的引用(解决方案资源管理 - >添加引用 - >选择.NET选项卡 - >从列表中选择System.ComponentModel.DataAnnotations)

You have to reference the assembly in which this namespace is defined (it is not referenced by default in the visual studio templates). Open your reference manager and add a reference to the System.ComponentModel.DataAnnotations assembly (Solution explorer -> Add reference -> Select .Net tab -> select System.ComponentModel.DataAnnotations from the list)

这篇关于为什么我不能引用System.ComponentModel.DataAnnotations?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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