mikeedwards83 / Glass.Mapper

Version 5 of the Glass mapping framework, the best ORM for Sitecore.
Apache License 2.0
124 stars 122 forks source link

Error when adding component to page - Empty strings are not allowed. Parameter name: fieldName #256

Open cubeberg opened 7 years ago

cubeberg commented 7 years ago

I'm getting an error (not in all cases - depending on the parent item) when an item is added to a page, before a datasource is assigned. I honestly can't figure out what's going on, but I assume it has something to do with mapping the wrong template. Sitecore 8.2 Initial Release

Example controller method:

public ActionResult BulletedListTwoColumn()
{
  var model = GetLayoutItem<IBulletedList>();
  return View(model);
}`

Example Model:
`[SitecoreType(TemplateId = "{33BC3B3B-1BF3-4F65-8BB9-A583E85F276E}", AutoMap = true)]
    public partial interface IBulletedList : IGlassBase
    {

        [SitecoreField(FieldId = "{C18A5917-8FE1-4D63-AF4A-E84EBE75D279}", FieldName="Bullets", FieldType = SitecoreFieldType.RichText)]
        string Bullets { get; set; }

    }`

Exception:

`Exception: System.ArgumentException
Message: Empty strings are not allowed.
Parameter name: fieldName
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.ArgumentNotNullOrEmpty(String argument, String argumentName)
   at Sitecore.Data.Items.BaseItem.get_Item(String fieldName)
   at Sitecore.Pipelines.RenderField.GetFieldValue.Process(RenderFieldArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
   at Glass.Mapper.Sc.DataMappers.SitecoreFieldStringMapper.RunPipeline(Field field) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\DataMappers\SitecoreFieldStringMapper.cs:line 99
   at Glass.Mapper.Sc.DataMappers.SitecoreFieldStringMapper.GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\DataMappers\SitecoreFieldStringMapper.cs:line 87
   at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.LoadValue(AbstractPropertyConfiguration propertyConfiguration) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:line 128
   at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.LoadAllValues() in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:line 141
   at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor..ctor(ObjectConstructionArgs args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:line 63
   at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.CreateInterfaceTask.Execute(ObjectConstructionArgs args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\CreateInterfaceTask.cs:line 54
   at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 77
   at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
   at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
   at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
   at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
   at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
   at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
   at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\AbstractService.cs:line 139
   at Glass.Mapper.Sc.SitecoreService.CreateType(Type type, Item item, Boolean isLazy, Boolean inferType, Dictionary`2 parameters, Object[] constructorParameters) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\SitecoreService.cs:line 506
   at Glass.Mapper.Sc.SitecoreService.CreateType[T](Item item, Boolean isLazy, Boolean inferType, Object[] constructorParameters) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\SitecoreService.cs:line 484
   at Glass.Mapper.Sc.SitecoreService.CreateType[T](Item item, Boolean isLazy, Boolean inferType) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\SitecoreService.cs:line 362
   at Glass.Mapper.Sc.AbstractSitecoreContext.GetCurrentItem[T](Boolean isLazy, Boolean inferType) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\AbstractSitecoreContext.cs:line 165
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
cubeberg commented 7 years ago

FYI - I was using build 4.2.1.188 but updated to 4.2.1.190, no improvement.

I forgot to mention - I am adding the Models dll for auto mapping.

var attributes = new AttributeConfigurationLoader("<projectname>.Models");

return new IConfigurationLoader[] { attributes };
mikeedwards83 commented 7 years ago

Hi

This is odd because the exception is being raised by the RenderField pipeline in Sitecore.

What makes this very odd is that we get an item from SC earlier in the process and then read the fields off this so to get to the point where you received the error and item must have existed.

Can you detail the steps I need to take to replicate this error?

cubeberg commented 7 years ago

That's the tough part - it's not consistent unfortunately. I replicate it on my local dev environment, sometimes but not always - even with the exact same steps. I'll keep working to see if I can find any more information.

I compiled a copy of glass.mapper.sc so I could add logging statements - RunPipeline is indeed called with no field name. Adding a check for an empty field name provided a short-term fix at least. I'm going to keep moving up the stack.

mikeedwards83 commented 7 years ago

I have added more logging to the renderfield call so that we can identify the field and item that threw the error. Maybe this will help. https://github.com/mikeedwards83/Glass.Mapper/commit/a3d8bcfd819cd54ac7469d2736026df75cfbe34b

cubeberg commented 7 years ago

Sorry for taking so long to check back in - that definitely helped - I don't need my custom version of the library anymore. I am still seeing errors - interestingly enough - it only happens on rich text fields.

dheeraj-palagiri-biggroup commented 7 years ago

This is still happening on RichText fields as parameter templates fields.

I can see the error mgs you are logging.

[MapperException: Failed to render field {xxxxx-D027-434C-BDEC-xxxx} on item {xxxxx-1959-41F1-A3D6-xxxx}]

This seems to work for couple of times after publish and starts to fail again. I tried disabling the cache thinking of an caching issue, still it throws the same error.

EstherTM commented 6 years ago

Anybody find a solution? I'm running into the same issue

mikeedwards83 commented 6 years ago

@EstherTM Are you also using Rich Text Fields?

rpdelacruz commented 6 years ago

Hi,

I notice that this issue is intermittent to some environments. In my case, this occurs when there is an unused rich text field existing in my shared class in your MVC. When I say unused, there is no rich text field to map in your template.

empty strings

I have no solid proof telling that this is really caused by rich texts field. But found a similar issue in the Known Issues section of Sitecore Developer Network site that was also caused by Rich Text fields. See Link: https://sdn.sitecore.net/Resources/Tools/V53_to_V6/Release%20Notes/Known%20Issues.aspx