While working on myAttendance.io project in mvc.net core 2.2, I was creating a company and wanted to generate Controller with Views. My company Class is as follows
To resolve this error I had to remove
public class Company : BaseModel
{
public string Logo { get; set; }
[DisplayName("Company Name")]
[Required]
[MaxLength(150)]
public string CompanyName { get; set; }
[RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessage = "Please enter a valid e-mail address")]
[EmailAddress(ErrorMessage = "Please enter valid email address.")]
[Required]
[MaxLength(150)]
public string Email { get; set; }
[Required]
[DataType(DataType.Url)]
[Url(ErrorMessage = "Invalid URL!")]
[MaxLength(150)]
public string Web { get; set; }
[Phone]
[Required]
[MaxLength(15)]
public string Phone { get; set; }
[Required]
[MaxLength(10)]
public string Currency { get; set; }
[Required]
[MaxLength(250)]
public string Address { get; set; }
}
When I tried adding New Scaffolded item, I got error sayingThere was an error running the selected code generator: 'Multiple custom attributes of the same type found'
To resolve this error I had to remove
[DataType(DataType.Url)]If we see model then I have already used
[Url(ErrorMessage = "Invalid URL!")]This same is applicable for followings
[EmailAddress(ErrorMessage = "Please enter valid email address.")] [Phone(ErrorMessage = "Please enter valide phone number.")]We have EmailAddress and PhoneNumber as Datatype also
[DataType(DataType.EmailAddress)] [DataType(DataType.PhoneNumber)]So Just make sure we have DataType or corresponding Tag to avoid 'Multiple custom attributes of the same type found.'

0 thoughts on "Mvc Core - Multiple custom attributes of the same type found - new scaffoled item - controller with view"