0

I was rewriting a code snippet from BlazorApp to BlazorApp Core based application. Suddenly now it throws an error on defining RangeAttribute.

Why am I getting the error:

"CS1729 'RangeAttribute' does not contain a constructor that takes 4 arguments TradeNow.Client"

My code is as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace TradeNow.Client.Pages.Adverts.Data
{
    public class SellBuy
    {
            [Required]
            [Range(typeof(SellBuyN), nameof(SellBuyN.Sell), typeof(SellBuyN), nameof(SellBuyN.Buy), ErrorMessage = "Select if you are buying or selling")]
            public SellBuyN SellBuyN { get; set; }
    }
    public enum SellBuyN { Sell, Unknown, net, smth, Buy }
}
2
  • 1
    It doesn't seem .Net 5 ever admitted 4 parameters in this constructor. Have you recently upgraded from a different version? Commented Dec 12, 2020 at 17:43
  • @derloopkat I was using preview before, also if I put one parameter, then error is same just states 1 argument.. Commented Dec 12, 2020 at 20:26

1 Answer 1

1

From the documentation at: https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.rangeattribute?view=net-5.0

You can see the constructor never take 4 arguments:

Constructors
CONSTRUCTORS
RangeAttribute(Double, Double)  
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

RangeAttribute(Int32, Int32)    
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

RangeAttribute(Type, String, String)    
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values and the specific type.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.