After upgrading framework pacakges: System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter 'length')

Vote:
 

Getting error:

After running following upgrades:

 

EPiServer.CMS.12.15.1 -> EPiServer.CMS.12.16.0

EPiServer.CMS.AspNetCore.12.11.0 -> EPiServer.CMS.AspNetCore.12.12.0

EPiServer.CMS.AspNetCore.HtmlHelpers.12.11.0 -> EPiServer.CMS.AspNetCore.HtmlHelpers.12.12.0

EPiServer.CMS.AspNetCore.Mvc.12.11.0 -> EPiServer.CMS.AspNetCore.Mvc.12.12.0

EPiServer.CMS.AspNetCore.Routing.12.11.0 -> EPiServer.CMS.AspNetCore.Routing.12.12.0

EPiServer.CMS.AspNetCore.Templating.12.11.0 -> EPiServer.CMS.AspNetCore.Templating.12.12.0

EPiServer.CMS.Core.12.11.0 -> EPiServer.CMS.Core.12.12.0

EPiServer.CMS.TinyMce.4.0.0 -> EPiServer.CMS.TinyMce.4.0.1

EPiServer.CMS.UI.12.15.0 -> EPiServer.CMS.UI.12.16.0

EPiServer.CMS.UI.Admin.12.15.0 -> EPiServer.CMS.UI.Admin.12.16.0

EPiServer.CMS.UI.AspNetIdentity.12.15.0 -> EPiServer.CMS.UI.AspNetIdentity.12.16.0

EPiServer.CMS.UI.Core.12.15.0 -> EPiServer.CMS.UI.Core.12.16.0

EPiServer.CMS.UI.Settings.12.15.0 -> EPiServer.CMS.UI.Settings.12.16.0

EPiServer.CMS.UI.Sources.12.15.0 -> EPiServer.CMS.UI.Sources.12.16.0

EPiServer.CMS.UI.VisitorGroups.12.15.0 -> EPiServer.CMS.UI.VisitorGroups.12.16.0

EPiServer.Forms.5.3.1 -> EPiServer.Forms.5.4.0

EPiServer.Forms.Core.5.3.1 -> EPiServer.Forms.Core.5.4.0

EPiServer.Forms.UI.5.3.1 -> EPiServer.Forms.UI.5.4.0

EPiServer.Framework.12.11.0 -> EPiServer.Framework.12.12.0

EPiServer.Framework.AspNetCore.12.11.0 -> EPiServer.Framework.AspNetCore.12.12.0

EPiServer.Hosting.12.11.0 -> EPiServer.Hosting.12.12.0

Getting errors as:

System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter 'length')
   at System.String.Substring(Int32 startIndex, Int32 length)
   at EPiServer.DataAccess.Internal.ContentDB.AssignDelayLoadedFactory(PropertyData property, String scopeName, ContentReference contentLink, CultureInfo language, Nullable`1 includedPropertyDefinitionId)
   at EPiServer.DataAccess.Internal.ContentAreaPropertyValueConverter.SetValue(PropertyContentArea property, PropertyDataRecord dataRecord, PropertyValueConverterContext context)
   at EPiServer.DataAccess.Internal.ContentDB.ReadPropertyData(PropertyData prop, DbDataReader reader, ContentReference contentLink, CultureInfo language)
   at EPiServer.DataAccess.Internal.ContentListDB.ReadCustomProperties(DbDataReader reader, Dictionary`2 allFetchedItems, Boolean isReadingVersions)
   at EPiServer.DataAccess.Internal.ContentListDB.ReadPublishedList(DbCommand cmd)
   at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass24_0`1.<Execute>b__0()
   at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
   at EPiServer.DataAccess.Internal.ContentListDB.LoadSpecificContentInstances(IList`1 contentLinks, Int32 languageBranchID)
   at EPiServer.Core.Internal.DefaultContentProvider.BatchLoad(IList`1 contentLinks, Func`2 dbLoader)
   at EPiServer.Core.Internal.DefaultContentProvider.LoadContents(IList`1 contentReferences, ILanguageSelector selector)
   at EPiServer.Core.ContentProvider.GetContentBatch(IList`1 batch, ILanguageSelector selector, List`1& contents, Dictionary`2& contentMap)
   at EPiServer.Core.ContentProvider.GetScatteredContents(IEnumerable`1 contentLinks, ILanguageSelector selector)
   at EPiServer.Core.Internal.ProviderPipelineImplementation.GetItems(ContentProvider provider, IList`1 contentLinks, LoaderOptions loaderOptions)
   at EPiServer.Core.Internal.DefaultContentLoader.GetChildren[T](ContentReference contentLink, LoaderOptions loaderOptions, Int32 startIndex, Int32 maxRows)
   at EPiServer.Core.Internal.DefaultContentLoader.GetChildren[T](ContentReference contentLink, LoaderOptions loaderOptions)
   at QDX.ContentExtensions.GetChildren[TPageData](ContentReference contentLink) in C:\Users\dsingh\source\repos\QDX\QDX\Business\Extensions\ContentExtensions.cs:line 346
   at AspNetCoreGeneratedDocument.Views_Shared__SiteHeader.<ExecuteAsync>g__DefaultMenuOption|8_2(SitePageData pagedata) in C:\Users\dsingh\source\repos\QDX\QDX\Views\Shared\_SiteHeader.cshtml:line 151
   at AspNetCoreGeneratedDocument.Views_Shared__SiteHeader.ExecuteAsync() in C:\Users\dsingh\source\repos\QDX\QDX\Views\Shared\_SiteHeader.cshtml:line 26
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.RenderPartialCoreAsync(String partialViewName, Object model, ViewDataDictionary viewData, TextWriter writer)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.PartialAsync(String partialViewName, Object model, ViewDataDictionary viewData)
   at Microsoft.AspNetCore.Mvc.Rendering.HtmlHelperPartialExtensions.Partial(IHtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at AspNetCoreGeneratedDocument.Views_Shared_Layouts_QDX__Site.ExecuteAsync() in C:\Users\dsingh\source\repos\QDX\QDX\Views\Shared\Layouts\QDX\_Site.cshtml:line 202
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|22_0(ResourceInvoker invoker, IActionResult result)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at QDX.Business.Services.HttpExceptionMiddleware.Invoke(HttpContext context) in C:\Users\dsingh\source\repos\QDX\QDX\Business\Services\HttpExceptionMiddleware.cs:line 25
   at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at QDX.Startup.<>c.<<Configure>b__6_1>d.MoveNext() in C:\Users\dsingh\source\repos\QDX\QDX\Startup.cs:line 225
--- End of stack trace from previous location ---

#295796
Feb 02, 2023 6:50
Vote:
 

I've investiagted the issue and found out that the cause is how the IPageCriteriaQueryService / ContentDB.AssignDelayLoadedFactory is handling nested blocks on the page level.
I've created a ticket in support, but in short, given following content structure (with existing content in database):

[ContentType]
public class SomePage : PageData
{
    public virtual BlockA BlockA { get; set; }
}

[ContentType]
public class BlockA : BlockData
{
    [AllowedTypes(typeof(BlockB))]
    public virtual ContentArea Links { get; set; }
}

[ContentType]
public class BlockB : BlockData
{
    [AllowedTypes(typeof(PageData))]
    public virtual ContentReference Link { get; set; }
}

While querying with IPageCriteriaQueryService the ContentDB.AssignDelayLoadedFactory throws and exception ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter 'length').

// Example hardcoded values, to isolate the error, however it is also present on real queries
PageReference pageLink = new PageReference(7); // Content ID of Home Page
string languageBranch = "en";
PropertyCriteriaCollection criterias = new PropertyCriteriaCollection
{
    new ()
    {
        Name = "PageLink",
        Type = PropertyDataType.PageReference,
        Condition = CompareCondition.Equal,
        Value = "1410", // Content ID of the Page
        Required = true,
    },
};

var pages = _pageCriteriaQueryService.FindPagesWithCriteria(pageLink, criterias, languageBranch);

The AssignDelayLoadedFactory method tries to execute following code:

char ch = includedPropertyDefinitionId.HasValue ? ':' : '(';
string lazyScopeName = scopeName.Substring(0, scopeName.LastIndexOf(ch) - 0);

which is not possible, due to scope being of value " .1376.322.", which does not contain neither colon or parenthesis.

The bug was reproduced by support, and it's available to be tracked here:
https://world.optimizely.com/Support/Bug-List/bug/CMS-26514

#295809
Feb 02, 2023 12:13
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.