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

  • Home
  • SEARCH
  • 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 8760853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:08:49+00:00 2026-06-13T15:08:49+00:00

I have an invoice object with the following property definition in it … [CustomValidation(typeof(InvoiceValidator),

  • 0

I have an invoice object with the following property definition in it …

[CustomValidation(typeof(InvoiceValidator), "ValidateInvoiceDate")]
 public DateTime InvoiceDate { get; set; }

When I do a postback in my MVC app I get an invoice object back then do this …

if(ModelState.IsValid)
{
   SaveInvoice(invoice);
}

My validator looks like this …

public static class InvoiceValidator
{
   public static ValidationResult ValidateInvoiceDate(DateTime invoiceDate, ValidationContext context)
   {
       // some validation code (omitted)
   }
}

My problem seems to be getting the dam thing to work as at the moment it simply throws an exception:

The CustomValidationAttribute method 'ValidateInvoiceDate' does not exist in type 'InvoiceValidator' or is not public and static.

This statement is clearly not right, the validator class exists and so does the method with the right modifiers (public, static). This is code i’ve used loads before and usually works fine but for some reason this time isn’t working.

Any ideas what else might cause this exception to be thrown?

Things i’ve tried:

clean solution and full rebuild (no errors at compile time).
rename the method / validator class and refactor attribute to new values then recompile
scratch head
ask on here

looks to me like my code isn’t being run correctly or something because I can’t see why a clearly declared public static method would result in an error saying it’s not declared other than that.

  • 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-13T15:08:50+00:00Added an answer on June 13, 2026 at 3:08 pm

    Ok found it ….

    It turns out that this whas wrong:

    [CustomValidation(typeof(InvoiceValidator), "ValidateInvoiceDate")]
    

    the “typeof(InvoiceValidator)” whilst it had the right type name it was specific enough and some T4 generated code was generating a type with the same name in a nearer scope so the compiler was matching it to that type.

    I’m a bit annoyed by this though … surely the compiler should have thrown an exception for an ambiguous type reference not a runtime error.

    Bad Microsoft !!

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

Sidebar

Related Questions

So, I have an Invoice object like so: public class Invoice { public virtual
I have an object Invoice which belongs to an Area: public class Invoice :
I have the following squeel query: i = Invoice.where{ paid == true } that's
If you have the following: Asp.Net MVC 2 project having object classes that define
I have the following nhibernate mapping <class name=Customer> <id name=Id> <generator class=native/> </id> <property
I have an object JobBreakdown that has_one :invoice . If a JobBreakdown has an
I have to create object model for following XMLs: XML sample 1: <InvoiceAdd> <TxnDate>2009-01-21</TxnDate>
I have invoice object and it has two properties, productDescription and productQuantity , here
I have /invoices/ controller and @service object. When /services/1/invoices/new is called, a new @invoice
I have following task for my project: I need to validate a java object,

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.