1

Closed

MVCControlsToolkit.Core.Extensions.Register breaks my project.

description

When I add the MVCControlToolkit nuget package, it adds a file ~/App_Start/MySuperPackage.cs.

If I comment-out the code in this new file, my project works fine.

If I put the code in this file back in, and then try to run my project, I get the following exception:

System.InvalidOperationException occurred
  HResult=-2146233079
  Message=Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: length
  Source=System.Web.WebPages
  StackTrace:
       at System.Web.Mvc.UnobtrusiveValidationAttributesGenerator.ValidateUnobtrusiveValidationRule(ModelClientValidationRule rule, IDictionary`2 resultsDictionary, String dictionaryKey)
       at System.Web.Mvc.UnobtrusiveValidationAttributesGenerator.GetValidationAttributes(IEnumerable`1 clientRules, IDictionary`2 results)
       at System.Web.Mvc.HtmlHelper.GetUnobtrusiveValidationAttributes(String name, ModelMetadata metadata)
       at System.Web.Mvc.Html.InputExtensions.InputHelper(HtmlHelper htmlHelper, InputType inputType, ModelMetadata metadata, String name, Object value, Boolean useViewData, Boolean isChecked, Boolean setId, Boolean isExplicitValue, String format, IDictionary`2 htmlAttributes)
       at System.Web.Mvc.Html.InputExtensions.TextBoxHelper(HtmlHelper htmlHelper, ModelMetadata metadata, Object model, String expression, String format, IDictionary`2 htmlAttributes)
       at System.Web.Mvc.Html.InputExtensions.TextBoxFor[TModel,TProperty](HtmlHelper`1 htmlHelper, Expression`1 expression, String format, IDictionary`2 htmlAttributes)
       at System.Web.Mvc.Html.InputExtensions.TextBoxFor[TModel,TProperty](HtmlHelper`1 htmlHelper, Expression`1 expression, String format)
       at System.Web.Mvc.Html.InputExtensions.TextBoxFor[TModel,TProperty](HtmlHelper`1 htmlHelper, Expression`1 expression)
       at ASP._Page_Views_Account_LogIn_cshtml.Execute() in v:\...\Views\Account\LogIn.cshtml:line 26
  InnerException: 
Closed Oct 31, 2014 at 9:32 PM by frankabbruzzese

comments

joshmouch wrote Mar 13, 2013 at 7:29 PM

If I change MySuperPackage.cs to look like the following, then I no longer get the above exception. I'm still testing if any other part of my application is affected.
using System;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using MVCControlsToolkit.Controls;
using MVCControlsToolkit.Core;
using MVCControlsToolkit.DataAnnotations;

[assembly: WebActivator.PreApplicationStartMethod(
    typeof(PatientArchive.App_Start.MySuperPackage), "PreStart")]

namespace PatientArchive.App_Start {
    public static class MySuperPackage {
        public static void PreStart() {
            //MVCControlsToolkit.Core.Extensions.Register();


            ModelBinders.Binders.DefaultBinder = (IModelBinder)new ExDefaultBinder();
            ModelMetadataProviders.Current = (ModelMetadataProvider)new DataAnnotationsModelMetadataProviderExt();
            //ModelValidatorProviders.Providers.Clear();
            //ModelValidatorProviders.Providers.Add((ModelValidatorProvider)new DataAnnotationsModelValidatorProviderExt());
            ModelValidatorProviders.Providers.Add((ModelValidatorProvider)new DataErrorInfoModelValidatorProvider());
            ModelValidatorProviders.Providers.Add((ModelValidatorProvider)new ClientDataTypeModelValidatorProviderExt());
            DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RangeAttribute), typeof(RangeAdapter));
            DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(DynamicRangeAttribute), typeof(DynamicRangeAdapter));
            DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(DateRangeAttribute), typeof(DateRangeAdapter));
            //ThemedControlsStrings.ResourceType = themedControlsResources;
            //ThemedControlsStrings.DefaultTheme = defaultTheme;

        }
    }
}

frankabbruzzese wrote Mar 14, 2013 at 9:02 PM

Do you use some validation package? The mvc Controls Toolkit Register A custom Validation provider, Maybe some other package register a custom data annotation validation provider so you have two of them...which is Not allowed and Cause The error You Have experienced. Anyway if This is The Case Your Correction Should Solve the Problem. however Maybe You have To Remove Also som Other Validation provider. I Added Some Of then just Because Of the clear...Let Me Know i you Register Other Providers (this Happens For instance If You Use Fluent Validation) and I Will inform You On Which providers To Keep And Which To remove.

wrote Oct 31, 2014 at 9:32 PM

wrote Oct 31, 2014 at 9:32 PM