为什么我不能引用System.ComponentModel.DataAnnotations? [英] Why can't I reference 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屋!