Why Can't I Reference System.Componentmodel.Dataannotations

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
Sample Image

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



Leave a reply



Submit