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 7014927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:35:08+00:00 2026-05-27T22:35:08+00:00

UPDATED: when i executing Unit Test project and then it will return Was unhandled

  • 0

UPDATED:
when i executing Unit Test project and then it will return Was unhandled This test result also contained an inner exception instead of “Assert.IsTrue failed. The Description field is required.” Result like (0 Pass, 1 FAIL, 1 Total) but we are not getting any exception at all if i debug with F11

    [TestMethod]
    [Asynchronous]
    [Description("Determines whether the selected or single property is valide using the validation context or validate single properties.")]
    public void ValidateSigleWithDataAnnotation()
    {
        LookupsServices lookupsservices = new LookupsServices();
        Lookups lookups = new Lookups() { Description = "", LookupReference = 2, DisplayOrder = 50};
        lookupsservices.Lookups.Add(lookups);

        //THIS IS NOT WORKING
        string message = ValidateProperties.ValidateSingle(lookups, "Description");
        Assert.IsTrue(message.Equals(""), message);
        //THIS IS WORKING
        var results = new List<ValidationResult>();
        Validator.TryValidateProperty(lookups.Description , new ValidationContext(lookups, null, null) { MemberName = "Description" }, results);
        Assert.IsTrue(results.Count == 0, results[0].ToString());
    }

Following is the Generic function to validate individual property

    public static string ValidateSingle<T>(T t, string PeropertyName) where T : class
    {
        string errorMessage = "";
        var ValidationMessages = new List<ValidationResult>();
        bool ValidationResult = Validator.TryValidateProperty(typeof(T).GetProperty(PeropertyName).Name,  new ValidationContext(t, null, null) { MemberName =  PeropertyName} , ValidationMessages);

        if (!ValidationResult) errorMessage += string.Format("\n{0}", ValidationMessages[0]);
        return errorMessage;
    }

Following is the Model where Description field id Required

public class Lookups
{
    public Lookups() { }
    [Key]
    public virtual int LookupReference { get; set; }
    [Required]
    public virtual string Description { get; set; }
    public virtual int? DisplayOrder { get; set; }
}

I am getting error “The Description field is required” if i am validating without Generic method, but why am not getting same error using Generic method?

Please Help me…..

  • 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-05-27T22:35:08+00:00Added an answer on May 27, 2026 at 10:35 pm

    Compare these two calls:

    // In the generic method
    Validator.TryValidateProperty(
        typeof(T).GetProperty(PeropertyName).Name, 
        new ValidationContext(t, null, null) { MemberName =  PeropertyName},
        ValidationMessages);
    
    // The working call
    Validator.TryValidateProperty(
        lookups.Description,
        new ValidationContext(lookups, null, null) { MemberName = "Description" },
        results);
    

    In the first form, you’re passing in the name of the property, i.e. “Description”. In the second form, you’re passing in the value of the property, i.e. “”. To make the first call look like the second, you’d need:

    typeof(T).GetProperty(PeropertyName).GetValue(t, null), 
    

    It’s not entirely clear to me whether that’s what you want (I haven’t used Validator myself) but it may be the answer.

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

Sidebar

Related Questions

Updated question, see below I'm starting a new project and I would like to
UPDATED Using RedDot CMS, linking to a 'sub-page' (page within a page) directly will
I just updated Maven from 2.0.9 to 2.2.1 and I'm getting the following exception
This is an issue with Javascript executing linearly on a single thread. using setTimeout(function(){},time);
I am studying this page: http://www.fxstreet.com/rates-charts/currency-rates/ which is continually updated by JavaScript with new
This must be a Delphi bug... I have a unit which is the basis
I've just updated a mvc 2 project to mvc 3 . I have the
I followed Apple's instructions to set up Unit Testing in my project. I followed
I am executing the follwing statements in php,mysql. The database isn't gettig updated. I
( Updated a little ) I'm not very experienced with internationalization using PHP, it

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.