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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:18:49+00:00 2026-05-17T02:18:49+00:00

I have edited the original question since the same error is occurring the difference

  • 0

I have edited the original question since the same error is occurring the difference being the implementation, I have now added Ninject to the mix.

I have created a class for the validation rules

public class AlbumValidator : AbstractValidator<Album> {
    public AlbumValidator() {
        RuleFor(a => a.Title).NotEmpty();
    }
}

I have created a ValidatorModule for Ninject

internal class FluentValidatorModule : NinjectModule {
    public override void Load() {
        AssemblyScanner.FindValidatorsInAssemblyContaining<AlbumValidator>()
            .ForEach(result => Bind(result.InterfaceType).To(result.ValidatorType).InSingletonScope());
    }
}

Here is my ValidatorFactory

public class NinjectValidatorFactory : ValidatorFactoryBase {
    public override IValidator CreateInstance(Type validatorType) {
        if (validatorType.GetGenericArguments()[0].Namespace.Contains("DynamicProxies")) {
            validatorType = Type.GetType(string.Format("{0}.{1}[[{2}]], {3}",
                validatorType.Namespace,
                validatorType.Name,
                validatorType.GetGenericArguments()[0].BaseType.AssemblyQualifiedName,
                validatorType.Assembly.FullName));
        }

        return Container.Get(validatorType) as IValidator;
    }

    IKernel Container { get; set; }
    public NinjectValidatorFactory(IKernel container) {
        Container = container;
    }
}

and the relevant parts from my Global

protected override void OnApplicationStarted() {
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);

        var factory = new NinjectValidatorFactory(Container);

        ModelValidatorProviders.Providers.Add(
            new FluentValidationModelValidatorProvider(factory));

        DataAnnotationsModelValidatorProvider
            .AddImplicitRequiredAttributeForValueTypes = false;
    }

    protected override IKernel CreateKernel() {
        return Container;
    }

    IKernel Container {
        get { return new StandardKernel(new FluentValidatorModule()); }
    }

I load the sample site click on the create new album link and then click the create button leaving the title empty I am then greeted with the error protected override void OnApplicationStarted() {
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);

        var factory = new NinjectValidatorFactory(Container);

        ModelValidatorProviders.Providers.Add(
            new FluentValidationModelValidatorProvider(factory));

        DataAnnotationsModelValidatorProvider
            .AddImplicitRequiredAttributeForValueTypes = false;
    }

    protected override IKernel CreateKernel() {
        return Container;
    }

    IKernel Container {
        get { return new StandardKernel(
            new Bootstrapper(),
            new FluentValidatorModule()); }
    }

I load up the create form and click create leaving the title empty low and behold an error

This property cannot be set to a null value.

The line it references is within the Entity Framework auto generated class, I traced the

Namespace.Contains("DynamicProxies")

and it was returning false, is this because I told EF to use a custom namespace SampleMusicStore.Web?

Or am I missing something else?

Cheers.

  • 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-17T02:18:49+00:00Added an answer on May 17, 2026 at 2:18 am

    The problem is that Entity Framework is generating dynamic proxies on your classes, and then your system is trying to validate against the proxy classes instead of the classes you defined.

    The way to resolve this is the same as this answer.

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

Sidebar

Related Questions

In response to the helpful comments, I have edited the original question (where I
Note: I have edited the original question based on comments and answers. My question
I have a .txt file created in Windows and now should be edited in
Edit: I've edited the sample to better resemble the problem I have, now the
Original question I have a class named RootViewController and my .h file has the
EDIT: I have edited my post... Working on a project (c#), I have a
i have an edited version of a config file specific for my machine. i
I have an XML EDITED: <?xml version=1.0 encoding=UTF-8?> <?xml-stylesheet type=text/xsl href=xsl.xslt?> <CATALOG> <CD> </CD>
I have the following case: Edited: removed link In IE7 gives me different view
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I

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.