CMS icon indicating copy to clipboard operation
CMS copied to clipboard

Problem if we sort by a field in a contents list and use media folder with Azure Blob Provider

Open ludoAlcala opened this issue 11 years ago • 0 comments

Hi,

when i sort my documents by a field (different of standard fields of media files), just before edit them. And after that i'm going to insert an image from media folder (with the azure blob provider), an error occured :

[NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.] Kooboo.CMS.Content.Persistence.AzureBlobService.<>c__DisplayClassc.<Execute>b__5(MediaContent it) +38 System.Linq.EnumerableSorter2.ComputeKeys(TElement[] elements, Int32 count) +147 System.Linq.EnumerableSorter1.Sort(TElement[] elements, Int32 count) +37 System.Linq.<GetEnumerator>d__0.MoveNext() +330 System.Linq.Enumerable.Count(IEnumerable1 source) +266 Kooboo.CMS.Content.Persistence.AzureBlobService.MediaContentProvider.Execute(IContentQuery1 query) +916 Kooboo.CMS.Content.Query.ContentQuery1.Count() +136 Kooboo.CMS.Content.Query.IContentQueryToPagedListExtension.ToPageList(IContentQuery1 contentQuery, Int32 pageIndex, Int32 pageSize, Boolean enablePaging) +107 Kooboo.CMS.Web.Areas.Contents.Controllers.MediaContentController.MediaContentGrid(String folderName, String search, Nullable1 page, Nullable1 pageSize, String sortField, String sortDir, String listType) +845 Kooboo.CMS.Web.Areas.Contents.Controllers.MediaContentController.Selection(String folderName, String search, Nullable1 page, Nullable1 pageSize, String sortField, String sortDir, String listType) +127 lambda_method(Closure , ControllerBase , Object[] ) +449 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +269 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +38 System.Web.Mvc.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10() +119 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +637 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +307 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +720 System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__19() +40 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +74 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

The problem is in Media Content Provider, method Execute, the actual code is trying to sort by a field that it doesn't exist in a media file (the previous one selected in the content list).

To resolve this case, i had to change the translator and add a check if the getProperty is not null :

 if (item.Descending)
                {
                    blobs = blobs.OrderByDescending(it => it.GetType().GetProperty(item.FieldName) != null ? it.GetType().GetProperty(item.FieldName).GetValue(it, null) : null);
                }
                else
                {
                    blobs = blobs.OrderBy(it => it.GetType().GetProperty(item.FieldName) != null ? it.GetType().GetProperty(item.FieldName).GetValue(it, null) : null);
                }

ludoAlcala avatar Oct 29 '14 17:10 ludoAlcala