Closed ChrisWeissRBA closed 8 years ago
This is odd because the error is coming from within Sitecore and not Glass. What is the path to the item you are trying to load?
Can you supply IPageBase?
public interface IPageBase : IContentBase
{
string MetaTitle { get; }
string MetaDescription { get; }
string MetaKeywords { get; }
string NavigationTitle { get; }
bool IncludeInGlobalNavigation { get; }
bool ShowBreadcrumbs { get; }
}
public interface IContentBase : ICmsEntity { Guid ID { get; } string Name { get; } string DisplayName { get; } string Path { get; } string Url { get; } string FullPath { get; } string TemplateName { get; } Guid TemplateId { get; } }
public interface ICmsEntity
{
}
Just in case...
PageBaseMap.cs
public class PageBaseMap : SitecoreGlassMap<IPageBase>
{
public override void Configure()
{
Map(config =>
{
ImportMap<IContentBase>();
config.AutoMap();
config.Field(f => f.MetaTitle).FieldName("Meta Title");
config.Field(f => f.MetaDescription).FieldName("Meta Description");
config.Field(f => f.MetaKeywords).FieldName("Meta Keywords");
config.Field(f => f.NavigationTitle).FieldName("Navigation Title");
config.Field(f => f.IncludeInGlobalNavigation).FieldName("Include In Global Navigation");
config.Field(f => f.ShowBreadcrumbs).FieldName("Show Breadcrumbs");
});
}
}
public class ContentBaseMap : SitecoreGlassMap
Looks like some info got lost in angle brackets for SitecoreContentRepository.cs. Let me try that again.
public TInterface GetContentItem< TInterface >(string contentGuid) where TInterface : class, IContentBase { Assert.ArgumentNotNullOrEmpty(contentGuid, "contentGuid"); var item = _cmsContext.GetItem(contentGuid); return item != null ? item.GlassCast< TInterface >() : null; }
Sorry Mike, here's the path of the item I'm trying to load: /sitecore/content/ClientName/Home
Running LinkManager.GetItemUrl(item); on the item (below) returned a ArgumentOutOfRangeException. Looks like I got some more digging to do. Thanks everyone!
var item = Sitecore.Context.Database.GetItem(contentGuid);
Chris
As this is an issue with Sitecore I am going to close this issue for now. If it turns out that this is a Glass problem please reopen the issue.
Context: I'm putting together a website using Sitecore 8.1 and Glass.Mapper 4.0.4.53. We're using SimpleInjector for IoC. I've mapped another item without issues before, however it was much simpler than the current item.
Below is where we're seeing the issue. Our GetItem() method is just calling the default Sitecore Database.GetItem method and is correctly returning the right item with the correct values in the fields. It is then given to GlassCast. When this happens, we'll see a couple "'((Castle.Proxies.IHomePageModelProxy)contentResponse.ContentItem).DesiredLink'" errors. (The other properties aren't accessible in debugger)
Outside of debugger, the error that's being returned when a (string) property is accessed is "startIndex cannot be larger than length of string."
(I've changed some names to keep the client's name out of this. I hope I didn't mess up a reference.)
SitecoreContentRepository.cs
public TInterface GetContentItem(string contentGuid)
where TInterface : class, IContentBase
{
Assert.ArgumentNotNullOrEmpty(contentGuid, "contentGuid");
var item = _cmsContext.GetItem(contentGuid);
return item != null ? item.GlassCast() : null;
}
IHomePageModel.cs
HomePageModelMap.cs
Stack Trace for startIndex exception
[ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex] System.String.Substring(Int32 startIndex, Int32 length) +13758496 Sitecore.Links.LinkBuilder.GetItemPathElement(Item item, SiteInfo site) +289 Sitecore.Links.LinkBuilder.BuildItemUrl(Item item) +72 Sitecore.Links.LinkProvider.GetItemUrl(Item item, UrlOptions options) +87 Glass.Mapper.Sc.DataMappers.SitecoreInfoMapper.MapToProperty(AbstractDataMappingContext mappingContext) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\DataMappers\SitecoreInfoMapper.cs:158 Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.LoadValues() in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:103 System.Lazyb 12() +80
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1.CreateValue() +709 System.Lazy
1.LazyInitValue() +191 Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.Intercept(IInvocation invocation) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:65 Castle.DynamicProxy.AbstractInvocation.Proceed() +448 Castle.Proxies.IHomePageModelProxy.get_SearchPlaceholderText() +138 OurSolutionRWD.Web.Controllers.HeaderFooterController.Header() in C:\Projects\OurSolution.com\OurSolutionRWD\OurSolutionRWD.Web\Controllers\HeaderFooterController.cs:52 lambda_method(Closure , ControllerBase , Object[] ) +87 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +229 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +35 System.Web.Mvc.<>cDisplayClass15.1 continuation) +453 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 continuation) +453 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +533