Why can't I reference System.ComponentModel.DataAnnotations?

后端 未结 14 1562
遥遥无期
遥遥无期 2020-11-28 08:47

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

using System.ComponentModel.DataAnnotations;         


        
相关标签:
14条回答
  • 2020-11-28 09:29

    I searched for help on this topic as I came across the same issue.

    Although the following may not be the Answer to the question asked originally in 2012 it may be a solution for those who come across this thread.

    A way to solve this is to check where your project is within the solution. It turns out for my instance (I was trying to install a NuGet package but it wouldn't and the listed error came up) that my project file was not included within the solution directory although showing in the solution explorer. I deleted the project from the directory out of scope and re-added the project but this time within the correct location.

    0 讨论(0)
  • 2020-11-28 09:29

    I also have this problem. That is very stupid when i add a namespace the same with System. I try to remove all references, but it is not resolved. I use "global::System.ComponentModel", it is working as well. When i remove my namespace, this problem has been resolved.

    0 讨论(0)
  • 2020-11-28 09:38

    If you don't have it in references (like I did not) you can also add the NuGet System.ComponentModel.Annotations to get the assemblies and resolve the errors. (Adding it here as this answer still top of Google for the error)

    0 讨论(0)
  • 2020-11-28 09:40

    If using .NET Core or .NET Standard

    use:

    Manage NuGet Packages..

    instead of:

    Add Reference...

    0 讨论(0)
  • 2020-11-28 09:41
    This error occurs when the reference to the "System.dll" got removed.Solution to the problem is very simple add the reference to "System.dll".The dll is normally available in the following location
    "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" .Add the reference your problem will get solved .
    
    0 讨论(0)
  • 2020-11-28 09:43

    I had same problem, I solved this problem by following way.

    Right click on page, select Property. in build action select Content.

    Hope that this solution may help you.

    0 讨论(0)
提交回复
热议问题