Why can't I reference 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)
type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel'
Ok, so a bypass to this issue was to run in the command of the project root dotnet restore
after VisualStudio did his conversion thing.
This solved the issue without having to convert to .NET core 2.0 or higher.
Unable to use data annotations
The .Net 4.6(also called vNext) web project has a dependency on Microsoft.AspNet.Mvc
. This pulls in a big tree of dependencies, the data annotations are under the package Microsoft.DataAnnotations
for using Data annotation in your project use Microsoft.DataAnnotations
in place of System.ComponantModel.DataAnnotations
.
Blazor WASM: Reference to System.ComponentModel.DataAnnotations causes linking failure on release build
I found that instead of referencing to System.ComponentModel.DataAnnotations.dll
I have to use a Nuget package with the same name and when I used Nuget package, linking error eliminated.
Why i can not use using System.ComponentModel.DataAnnotations in my class?
I think you forgot to add assembly reference in your application.
Go to Reference->Add Reference-> Select System.ComponentModel.DataAnnotations assembly to your application.
Then use the namespace in your application
using System.ComponentModel.DataAnnotations;
Please find screenshot for reference
Why classes that implements IValidatableObject requires reference to System.ComponentModel.DataAnnotations when used in another class library?
Most custom attributes (including RequiredAttribute
) don't have any influence on compilation. Whereas the possible types for an object (its own type, base classes, and any interfaces) can influence things like method overload selection.
As such, the compiler needs to actually know all of those types when compiling an assembly that uses your Customer
class.
Related Topics
How to Get All the Possible 3 Letter Permutations
How to Ensure Entries with Non-Overlapping Time Ranges
How to Get All Input Elements in a Form with HTMLagilitypack Without Getting a Null Reference Error
Is Idependencyresolver an Anti-Pattern
Should I Use Return/Continue Statement Instead of If-Else
Mvc-Web API: 405 Method Not Allowed
Generate PDF from ASP.NET from Raw HTML/CSS Content
In C# Wpf, Why Is My Tabcontrol's Selectionchanged Event Firing Too Often
Publish .Net Core App as Portable Executable
Scraping Data Dynamically Generated by JavaScript in HTML Document Using C#
Irregular Shaped Windows Form (C#)
Linq: How to Exclude Condition If Parameter Is Null