c# - 我该如何解决这个问题?单元类型存在于两个dll文件中

标签 c# asp.net-mvc visual-studio dll controller

我目前正在学习使用 Visual Studio 11 beta 的教程。尝试在我的一个类中设置字段值的最大长度时:

[MaxLength(50)]
public string LastName { get; set; }

它出错并且不会让我编译,因为 MaxLength() 函数存在于两个地方:

Error 4 The type 'System.ComponentModel.DataAnnotations.MaxLengthAttribute' exists in both 'c:\Users\me\Documents\Visual Studio 11\ContosoUniversity\packages\EntityFramework.4.1.10331.0\lib\net40\EntityFramework.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'

我已尝试删除这两个文件,但这只会导致更多问题,因为我项目中的其他代码依赖于它们。

有什么方法可以告诉它使用其中一个吗?

所有这些方法似乎都不适合我。请参阅答案下的评论。还有其他想法吗?

谢谢

最佳答案

在代码顶部使用 using:

using MaxLength = System.ComponentModel.DataAnnotations

关于c# - 我该如何解决这个问题?单元类型存在于两个dll文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10840872/

相关文章:

asp.net - 在 foreach 中使用 DisplayFor

git - 带有 Visual Studio Team Services 的 TeamCity 和 git 存储库

c# - 在不使用另一个变量的情况下交换两个数字

c# - 使用 linq 取出 foreach

asp.net - 静态文件请求不会引发application_error事件

git - 本地 Git 存储库已存在

.net - 为什么 Visual Studio 在 Azure DevOps checkin 时排除 BIN 和 OBJ 文件夹

c# - 使用 Python.Net 自动化 Microsoft word

c# - 为什么在 Java(和其他)中大写类名只是一个建议而不是规则?

c# - 在 DropDownListFor 上添加搜索功能