A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

ProxyClass Not able to Convert String to CustomType

Vote:
 

Hi,

I have class which has Custom Property Tag and Defines BackingType(PropertyTag). It works in Edit Mode in UI and converts everything alright but when i try to load it in content area i get the error. I have provided the error below. Please have a look provide me the solution. 

[ContentType(DisplayName = "Filtered Section Block", GUID = "538683C8-F423-4181-9196-F8E082F9CECD", Description = "This section block will be populated based on filter defined")]
    public class FilteredSectionBlock : BlockData, ISection
    {
        [Required]
        [Display(Description = "The presentation layout of this section", Order = 10)]
        [SelectOne(SelectionFactoryType = typeof(EnumSelectionFactory))]
        public virtual SectionLayout Layout { get; set; }

        [Display(Order = 20, Description = "Start typing the topic name to see suggestions. Allows multiple.")]
        [AutoSuggestTags(typeof(TopicSelectionQuery))]
        public virtual string Topics { get; set; }

        [Display(Order = 30, Description = "Select Competitoin to filter the content of section block")]
        [LinkedAutoSelection(typeof(CompetitionTagSelectionQuery), null, null, new[] { "/season/topic" })]
        [BackingType(typeof(PropertyTag))]
        public virtual Tag Competition { get; set; }

        [LinkedAutoSelection(typeof(SeasonTagSelectionQuery), new[] { "competition" }, "/season/topic", null)]
        [Display(Order = 40, Description = "Select season to filter the content of section block")]
        [BackingType(typeof(PropertyTag))]
        public virtual Tag Season { get; set; }

        [AutoSuggestTags(typeof(ClubTagSelectionQuery))]
        [Display(Order = 50, Description = "Specific club/s related to this content. Start typing a club name to see suggestions. Allows multiple.")]
        [BackingType(typeof(PropertyTagList))]
        public virtual TagList Clubs { get; set; }

        [BackingType(typeof(PropertyStringList))]
        [Display(Order = 60, Description = "Additoinal Keywords matching in content. Allows multiple. Enter seperate keyword in different line.")]
        public virtual string[] Keywords { get; set; }

        [Display(Order = 65, Name = "Content Type", Description = "Show only content of specific type")]
        [SelectOne(SelectionFactoryType = typeof(EnumSelectionFactory))]
        public virtual ContentPageType ContentPageType { get; set; }

        [SelectOne(SelectionFactoryType = typeof(SponsorSelectionFactory))]
        [Display(Order = 70)]
        public virtual ContentReference Sponsor { get; set; }

        public string Name => this.Name();

        public SponsorBlock GetSponsor() => Sponsor?.Get();

        public IEnumerable GetContent()
        {
            return ContentSearchService.GetFilteredSectionContent(new Fitler.SectionBlockFilterModel
            {
                ContentPageType = ContentPageType,
                Keywords = Keywords,
                Competition = Competition,
                Season = Season,
                Topics = TagHelper.GetAllContentReferences(Tags.Topic, Topics ?? string.Empty),
                Clubs = Clubs
            });
        }
    }
at Castle.Proxies.FilteredSectionBlockProxy.get_Competition()
   at NRL.Web.Business.Models.Blocks.FilteredSectionBlock.GetContent() in C:\Dev\NRl\nrl.website\Source\NRL.Web.Business\Models\Blocks\FilteredSectionBlock.cs:line 67
   at ASP._Page_Views_Shared_Blocks_SectionBlock_cshtml.Execute() in C:\Dev\NRl\nrl.website\Source\NRL.Web\Views\Shared\Blocks\SectionBlock.cshtml:line 21
   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.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model)
   at ASP._Page_Views_Shared_Blocks_FilteredSectionBlock_cshtml.Execute() in C:\Dev\NRl\nrl.website\Source\NRL.Web\Views\Shared\Blocks\FilteredSectionBlock.cshtml:line 4
   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 EPiServer.Web.Mvc.ViewExtensions.Render[T](IView view, ViewEngineResult viewEngineResult, ViewContext context, TextWriter writer, T data)
   at EPiServer.Web.Mvc.Internal.DefaultMvcContentRenderer.HandleRenderTemplateWithViewEngine(HtmlHelper helper, IContentData contentData, TemplateModel templateModel)
   at EPiServer.Web.Mvc.Internal.DefaultMvcContentRenderer.Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
   at EPiServer.Web.Mvc.Html.IContentDataExtensions.RenderContentData(HtmlHelper html, IContentData contentData, Boolean isContentInContentArea, TemplateModel templateModel, IContentRenderer contentRenderer, Func`1 partialRequest)
   at EPiServer.Web.Mvc.Html.IContentDataExtensions.RenderContentData(HtmlHelper html, IContentData contentData, Boolean isContentInContentArea, TemplateModel templateModel, IContentRenderer contentRenderer)
   at EPiServer.Web.Mvc.Html.ContentAreaRenderer.RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, String templateTag, String htmlTag, String cssClass)
   at EPiServer.Web.Mvc.Html.ContentAreaRenderer.RenderContentAreaItems(HtmlHelper htmlHelper, IEnumerable`1 contentAreaItems)
   at EPiServer.Web.Mvc.Html.ContentAreaRenderer.Render(HtmlHelper htmlHelper, ContentArea contentArea)
   at EPiServer.Web.Mvc.Html.ContentAreaExtensions.RenderContentArea(HtmlHelper htmlHelper, ContentArea contentArea)
   at ASP.util_views_shared_displaytemplates_contentarea_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in http://server/Util/Views/Shared/DisplayTemplates/ContentArea.ascx:line 4
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.Control.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
#181915
Sep 05, 2017 6:40
Vote:
 

On further debug I am having this issue while creating FilteredSectionBlock

[InvalidCastException: Unable to cast object of type 'System.String' to type 'NRL.Web.Business.Models.Properties.Tag'.]
   Castle.Proxies.FilteredSectionBlockProxy.get_Competition() +155

[TargetInvocationException: Property accessor 'Competition' on object 'Castle.Proxies.FilteredSectionBlockProxy' threw the following exception:'Unable to cast object of type 'System.String' to type 'NRL.Web.Business.Models.Properties.Tag'.']
   System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +378
   EPiServer.Validation.DataAnnotationsValidator`1.ValidateInstance(Object instance, List`1 validationResult, ValidationContext validationContext) +456
   EPiServer.Validation.DataAnnotationsValidator`1.Validate(T instance) +117
   EPiServer.Validation.Internal.ContextValidatorWrapper`2.Validate(Object instance, Object context) +249
   EPiServer.Validation.Internal.ValidationService.ValidateRecursively(Object instance, Object context, HashSet`1 visitedInstances) +307
   EPiServer.Validation.Internal.ValidationService.Validate(Object instance, T context) +54
   EPiServer.Core.ContentProvider.Validate(IContent content, ContentSaveValidationContext saveValidationContext) +215
   EPiServer.Core.Internal.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access) +662
   EPiServer.Cms.Shell.Service.Internal.ContentService.Save(IContent content, SaveAction saveAction, AccessLevel accessLevel) +55
   EPiServer.Cms.Shell.Service.Internal.ContentService.Save(IContent content, SaveAction saveAction) +18
   EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.CreateContent(ContentReference parentLink, Int32 contentTypeId, Nullable`1 resourceFolderId, Boolean createAsLocalAsset, String name, IDictionary`2 properties, SaveAction saveAction) +182
   EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.Create(ContentReference parentLink, Int32 contentTypeId, Nullable`1 resourceFolderId, Boolean createAsLocalAsset, String name, IDictionary`2 properties, Boolean autoPublish) +158
   EPiServer.Cms.Shell.UI.Rest.Internal.ContentDataStore.Post(PostContentModel entity) +280
   lambda_method(Closure , ControllerBase , Object[] ) +104
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +228
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +228
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   EPiServer.Shell.Services.Rest.RestControllerBase.EndExecute(IAsyncResult asyncResult) +38
   EPiServer.Shell.Services.Rest.RestHttpHandler.EndProcessRequest(IAsyncResult result) +28
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9772985
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
#181917
Sep 05, 2017 10:12
Vote:
 

Hi,

It looks like Competition property should be of type string instead of Tag, since PropertyTag must be returning a string?

public virtual Tag Competition { get; set; }

Try with this instead:

public virtual string Competition { get; set; }

BR,

Marija

#183007
Oct 03, 2017 12:01
Vote:
 

Hi Marija,

Thanks for reply. I have figured out the issue and it was related to backing type registration in episerver. In Admin section the registered the type of Competition was String i updated the type to Tag and TagList for other properties and it started working.

Cheers

Ali, Murtaza

#183030
Oct 03, 2017 14:54
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.