我目前正在学习使用 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/