Closed
Description
In .net 9
In validation of a blazor page on compile I get a runtime exception, Constant Expression, when using this statement
MessageStore?.Add ( () => nameof ( Subscriber.Topic ), localMsg.TopicRequired );
Subscriber is a simple class
`
class Subscriber
{
public string Topic {get; set;}
public string ClientId {get; set;}
}
`
All that I want to do is let name of retrieve the name of the field, yet in order to do this I have to use the much more complicated statement
MessageStore?.Add ( new FieldIdentifier ( Model, nameof ( Subscriber.Topic ) ), localMsg.NumberOfTopicsClientIdMustMatch );
Where Model is the blazor page model and is of type Subscriber.
Add takes a FieldIdentifier or Expression<Func> accessor. Why can't the add method use a simple nameof rather than the more complicated FieldIdentifier and the accessor method?