Skip to main content
Tweeted twitter.com/StackTridion/status/1240382601178873857
added 16 characters in body; edited title
Source Link
Atila Sos
  • 6.3k
  • 2
  • 16
  • 26

How to resolve a Error on Publishingpublishing a Page in tridion core serviceTridion Core Service?

Unable to cast object of type 'Tridion.ContentManager.CommunicationManagement.Publication' to type 'Tridion.ContentManager.CommunicationManagement.PublishingTarget' Error:

Unable to cast object of type 'Tridion.ContentManager.CommunicationManagement.Publication' to type 'Tridion.ContentManager.CommunicationManagement.PublishingTarget'

How to resolve a Error on Publishing a Page in tridion core service?

Unable to cast object of type 'Tridion.ContentManager.CommunicationManagement.Publication' to type 'Tridion.ContentManager.CommunicationManagement.PublishingTarget'

Error on publishing a Page in Tridion Core Service?

Error:

Unable to cast object of type 'Tridion.ContentManager.CommunicationManagement.Publication' to type 'Tridion.ContentManager.CommunicationManagement.PublishingTarget'

Became Hot Network Question
edited title
Link
Jeevitha
  • 448
  • 2
  • 8

How to resolve a Error on Publishing a Page in tridion core service?

Source Link
Jeevitha
  • 448
  • 2
  • 8

How to resolve a Error on Publishing a Page in tridion core service

 public void PublishComponent()
    {
        string domainName = System.Configuration.ConfigurationSettings.AppSettings["domainName"];
        string userName = System.Configuration.ConfigurationSettings.AppSettings["userName"];
        string passowrd = System.Configuration.ConfigurationSettings.AppSettings["passowrd"];
        timestamp = DateTime.Now.ToString("dd:MM:yy h:mm:ss tt").Replace(":", "_").Replace(" ", "");
        string content = string.Empty;
        client = CoreServiceClientFactory.GetClient();
        string[] pageList = System.IO.File.ReadAllLines(Environment.CurrentDirectory + "\\" + "pagepublish.txt");
        //string[] pageList = System.IO.File.ReadAllLines(Environment.CurrentDirectory + "\\" + "publish.txt");
        // string[] publishTargets = new string[] { "live", "preview" };
        string[] publishTargets = new string[] { "tcm:0-1109-1" };
        // string[] publishTargets = { "tcm:0-30-1" };
        int i = 1;
        int breakValue = 0;
        foreach (var tcmid in pageList)
        {
            string componenttcmid = tcmid;
            string[] page = new string[] { tcmid };
            Console.Write("Start- " + componenttcmid + " - " + i + " of " + pageList.Count());
            Console.WriteLine();

            PublishInstructionData publishInstructionData = new PublishInstructionData
            {
                RenderInstruction = new RenderInstructionData(),
                ResolveInstruction = new ResolveInstructionData()
            };
            if (breakValue == 10)
            {
                breakValue = 0;
                Thread.Sleep(5000);
            }
            try
            {
                client.Publish(page, publishInstructionData, publishTargets, PublishPriority.Normal, new ReadOptions());
                Console.WriteLine(componenttcmid + "Published");
                Log(componenttcmid, "publish");
                Console.WriteLine();

            }
            catch (Exception ex)
            {
                Log(componenttcmid + " - " + ex.Message + ex.StackTrace, "publisherror");
                Log(componenttcmid, "failedpublish");
                //client.Update(ComponentContent, new ReadOptions());
                Console.WriteLine("Failed" + componenttcmid);
            }
            breakValue++;
            i++;
        }
    }

Unable to cast object of type 'Tridion.ContentManager.CommunicationManagement.Publication' to type 'Tridion.ContentManager.CommunicationManagement.PublishingTarget'