locked
Cannot retrieve property 'Name' because localization failed. I need to override the retrieving method. RRS feed

  • Question

  • User-277619977 posted

    problem situation:

    Cannot retrieve property 'Name' because localization failed.  Type 'Resources.Resources' is not public or does not contain a public static string property with the name 'Naam'.

    I have this problem in my asp.mvc website.

    for my model i use DataAnnotations. Like this:

    [Display(Name = "Naam", ResourceType = typeof(Resources.Resources))]
    [StringLength(200, ErrorMessageResourceName = "Naam_StringLength", ErrorMessageResourceType = typeof(Resources.Resources))]
    public System.String Naam { get; set; }

    Now this works fine if my word 'Naam' exists inside my resource file.

    But is is possible to override this retrieving method.

    Because if it's not inside the resourcefile i can return the resourcename in UPPERCASE for example. (instead of this error above)

    In this case i would like to return NAAM.

    Is this possible ?

    This is my Stacktrace:

    at System.ComponentModel.DataAnnotations.LocalizableString.<>c__DisplayClass7.<GetLocalizableValue>b__1()
    at System.ComponentModel.DataAnnotations.LocalizableString.GetLocalizableValue()
    at System.ComponentModel.DataAnnotations.DisplayAttribute.GetShortName()
    at System.Web.Mvc.DataAnnotationsModelMetadataProvider.CreateMetadata(IEnumerable`1 attributes, Type containerType, Func`1 modelAccessor, Type modelType, String propertyName)
    at System.Web.Mvc.AssociatedMetadataProvider.GetMetadataForProperty(Func`1 modelAccessor, Type containerType, PropertyDescriptor propertyDescriptor)
    at System.Web.Mvc.AssociatedMetadataProvider.GetMetadataForProperty(Func`1 modelAccessor, Type containerType, String propertyName)
    at System.Web.Mvc.ModelMetadata.GetMetadataFromProvider(Func`1 modelAccessor, Type modelType, String propertyName, Type containerType)
    at System.Web.Mvc.ModelMetadata.FromLambdaExpression[TParameter,TValue](Expression`1 expression, ViewDataDictionary`1 viewData)
    at System.Web.Mvc.Html.LabelExtensions.LabelFor[TModel,TValue](HtmlHelper`1 html, Expression`1 expression, String labelText)
    at System.Web.Mvc.Html.LabelExtensions.LabelFor[TModel,TValue](HtmlHelper`1 html, Expression`1 expression)
    at ASP._Page_Views_Kanon__Basisgegevens_cshtml.Execute() in c:\Projects\InoPowerV5.0\MVCWebsite\MVC3-Website\Views\Kanon\_Basisgegevens.cshtml:line 12
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
    at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
    at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
    at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
    at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)

    Wednesday, November 23, 2011 3:52 AM

Answers