Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:58:27+00:00 2026-06-04T03:58:27+00:00

I have the following problem, I’m trying to use FluentValidation in Windows Phone to

  • 0

I have the following problem, I’m trying to use FluentValidation in Windows Phone to validate if a string is a valid username.

The problem I have is that the validator value has the type string which has to be tested. In all the examples I can find it’s always a property of the object that is being tested like this RuleFor(customer => customer.Surname).NotEmpty();

When I run this code I get the following error

Code:

public class UsernameValidator : AbstractValidator<string>
{
    public UsernameValidator()
    {
        RuleFor(username => username).NotNull().NotEmpty().WithMessage("Enter a username");
        RuleFor(username => username).Matches("^[a-zA-Z0-9_]*$").WithMessage("Only letters and numbers");
        RuleFor(username => username).Length(3, 30).WithMessage("Minimum length is 3");
    }
}

Error:

FluentValidation for WP7 can only be used with expressions that reference public properties, ie x => x.SomeProperty
   at FluentValidation.Internal.Extensions.CompilePropertyGetterExpression(LambdaExpression expression, Type delegateType)
   at FluentValidation.Internal.Extensions.Compile[TDelegate](Expression`1 expression)
   at FluentValidation.Internal.PropertyRule`1.Create[TProperty](Expression`1 expression, Func`1 cascadeModeThunk)
   at FluentValidation.AbstractValidator`1.RuleFor[TProperty](Expression`1 expression)
   at WorldChat.ViewModels.Validators.UsernameValidator..ctor()
   at WorldChat.ViewModels.RegisterViewModel.get_ErrorUsername()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] index, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at System.Windows.CLRPropertyListener.get_Value()
   at System.Windows.PropertyAccessPathStep.ConnectToPropertyInSource(Boolean isSourceCollectionViewCurrentItem)
   at System.Windows.PropertyAccessPathStep.ConnectToProperty()
   at System.Windows.PropertyAccessPathStep.ReConnect(Object newSource)
   at System.Windows.PropertyPathListener.ReConnect(Object source)
   at System.Windows.Data.BindingExpression.SourceAcquired()
   at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
   at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
   at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
   at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
   at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
   at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
   at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
   at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)
   at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)
   at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent, Byte bCanCreateParent)
   at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)
   at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
   at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
   at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
   at Microsoft.Phone.Controls.PhoneApplicationFrame.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:58:29+00:00Added an answer on June 4, 2026 at 3:58 am

    I found a workaround, it requires you to have a extra string wrapper class.

    ValidationString.cs

    public class ValidationString
    {
        public string value { get; set; }
    
        public ValidationString(string value)
        {
            this.value = value;
        }
    }
    

    In the username validator class I add a static method IsUsername

    public class UsernameValidator : AbstractValidator<ValidationString>
    {
        public UsernameValidator()
        {
            RuleFor(username => username.value).NotNull().NotEmpty().WithMessage("Enter a username");
            RuleFor(username => username.value).Matches("^[a-zA-Z0-9_]*$").WithMessage("Only letters and numbers");
            RuleFor(username => username.value).Length(3, 30).WithMessage("Minimum length is 3");
        }
    
        internal static bool IsUsername(string value)
        {
            return new UsernameValidator().Validate(new ValidationString(value)).IsValid;
        }
    }
    

    And now I will be both able to use this UsernameValidator on a string as well as I’m still able to use it another validater, for example a registration validator

    public class RegisterValidator : AbstractValidator<User>
    {
        public RegisterValidator()
        {
            RuleFor(user => user.Username).Must(UsernameValidator.IsUsername);
            // some more rules
        }
    }
    

    If you don’t want to use your UsernameValidator in other validation classes you can leave the IsUsername method out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have the following problem, from c++ I send huge string[] to java. huge
I have following problem: I have a very long string String str = abcdefghiart----
I have following problem: Input String 1 : A[SPACE]B[SPACE]C[SPACE][SPACE]D[SPACE][SPACE]E Input String 2 : 1-
I have the following problem: String explosion_type = this.prefs.getString(explosion_type, ring_explosion); BitmapFactory.Options optionsExplosion = new
i have following problem To decode the Biquinary code use the number 5043210. At
HI Guys, I have following problem. I'm trying to connect from my Iphone app
I have following problem. I want to make some graphics in c# windows form.
i have following problem: i look for a variable to work with that comes
I have following problem. I use this tutorial to creating a multiple file uploader:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.