+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Getting this error when trying to add a comment to a blog post.

Getting this error when trying to add a comment to a blog post.

4 posts, 0 answered
  1. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    09 Nov 2009
    Link to this post

    http://www.newpatriotjournal.com/teapartypatriotsblog/09-11-04/How_to_deal_with_a_bad_renter_representative.aspx

    Unable to cast object of type 'Telerik.Cms.Engine.Data.Comment' to type 'Telerik.Cms.Engine.IContent'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Unable to cast object of type 'Telerik.Cms.Engine.Data.Comment' to type 'Telerik.Cms.Engine.IContent'.

    Source Error:

    Line 21:     void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)
    Line 22: {
    Line 23: Telerik.Cms.Engine.IContent cnt = (Telerik.Cms.Engine.IContent)e.CommandArguments;
    Line 24: if (e.CommandName == "CreateContent" && cnt.ProviderName == "Blogs")
    Line 25: {

    Source File: d:\inetpub\wwwroot\NewPatriotJournal\Global.asax    Line: 23

    Stack Trace:

    [InvalidCastException: Unable to cast object of type 'Telerik.Cms.Engine.Data.Comment' to type 'Telerik.Cms.Engine.IContent'.]
    ASP.global_asax.ContentManager_Executing(Object sender, ExecutingEventArgs e) in d:\inetpub\wwwroot\NewPatriotJournal\Global.asax:23
    Telerik.ManagerBase`1.OnExecuting(Object sender, ExecutingEventArgs args) +148
    Telerik.Cms.Engine.Data.Providers.DefaultProvider.OnExecuting(ExecutingEventArgs args, Boolean fireEvents) +37
    Telerik.Cms.Engine.Data.EventExecuteController.tran_BeginCommit(Object sender, EventArgs e) +82
    Nolics.ORMapper.Base.Transaction.OnBeginCommit() +36
    Nolics.ORMapper.Base.Transaction.Commit(Boolean fCleanIfSuccess) +101
    Telerik.Cms.Engine.Data.Providers.DefaultProvider.SaveComment(IComment comment) +392
    Telerik.Cms.Engine.ContentManager.SaveComment(IComment comment) +94
    Telerik.Cms.Engine.WebControls.CommentsList.SubmitButton_Command(Object sender, CommandEventArgs e) +1185
    System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +102
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981


    Version Information: Microsoft .NET Framework Version:2.0.50727.4016; ASP.NET Version:2.0.50727.4016
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Nov 2009
    Link to this post
    Hi Rob Gaudet,

    You have some custom logic under global.asax file that cause the error. Try changing the logic as shown below:

    void global_asax_Executing(object sender, Telerik.ExecutingEventArgs e)
    {
        
        switch(e.CommandName)
        {
            case "CreateContent":
             // do something
                break;
            case "UpdateContent":
                // do something.
                break;
            case "CreateComment":
                Telerik.Cms.Engine.IContent currentContent = e.CommandArguments as Telerik.Cms.Engine.IContent;
                // do something
                break;
        }
    }

    We are creating a switch loop for each CommandName. Another option is shown below:

    if (e.CommandName == "CreateContent" || e.CommandName == "UpdateContent")
            {
                //take the IContent Item from the command arguments
                Telerik.Cms.Engine.IContent cnt = e.CommandArguments as Telerik.Cms.Engine.IContent;
                //chech if there is a content and if it belongs to the news provider
                if (cnt != null && cnt.ProviderName == "Blogs")
                {
                    // do something
                }
            }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    09 Nov 2009
    Link to this post
    Thanks,

    This is what I have in the Executing Event.. in global asax that is breaking. Where does the profile properties I am getting go?

      void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)
        {
            Telerik.Cms.Engine.IContent cnt = (Telerik.Cms.Engine.IContent)e.CommandArguments;
            if (e.CommandName == "CreateContent" | cnt.ProviderName == "Blogs")
            {
                string username = Telerik.Security.UserManager.Default.GetUser().UserName;
                ProfileBase profile = ProfileBase.Create(username, true);
                string firstname = profile.GetPropertyValue("FirstName").ToString();
                string lastname = profile.GetPropertyValue("LastName").ToString();
                cnt.SetMetaData("Author", firstname + " " + lastname);
            }
        }
  4. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    09 Nov 2009
    Link to this post
    Okay thanks. I think I got it.


        void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)
        {
            if (e.CommandName == "CreateContent" || e.CommandName == "UpdateContent")
            {
                //take the IContent Item from the command arguments
                Telerik.Cms.Engine.IContent cnt = e.CommandArguments as Telerik.Cms.Engine.IContent;
                //chech if there is a content and if it belongs to the news provider
                if (cnt != null && cnt.ProviderName == "Blogs")
                {
                    // do something
                    string username = Telerik.Security.UserManager.Default.GetUser().UserName;
                    ProfileBase profile = ProfileBase.Create(username, true);
                    string firstname = profile.GetPropertyValue("FirstName").ToString();
                    string lastname = profile.GetPropertyValue("LastName").ToString();
                    cnt.SetMetaData("Author", firstname + " " + lastname);
                }
            }
        }
Register for webinar
4 posts, 0 answered