Event System Error with Tridion UI (Experience Manager)

203 Views Asked by At

We are publishing extra page using event system on publishing event of pages. It is working well when we publish a page from the CME. When we create a page using Tridion UI, it is created and published as expected but the event system throws error when it tries to create a target type object.

 try
            {
                foreach (var t in e.Targets)
                {
                    var targets = new List<TargetType>();

                   some logic

                    targets.Add(new TargetType(t.Id, page.Session)); // error is in this line

                    PublishInstructionBase pib = e.PublishTransactions.First().Instruction;
                    PublishInstruction pi = new PublishInstruction(page.Session);
                    pi.StartAt = pib.StartAt;
                    pi.RollbackOnFailure = pib.RollbackOnFailure;


                    PublishEngine.Publish(
                        items,
                        pi,
                        targets,
                        PublishPriority.Low
                    );
                }

            }

Exception we are getting is InvalidURIException

Both t and Session are not definitely not null which we verified by writing log over there.

Please do suggest what we can to fix the issue?

We manage to fix that by little hack putting code in try catch and creating target type manually if there is exception as we do know Tridion UI publish to staging only initially.

Thanks, Vikas Kumar

2

There are 2 best solutions below

0
On

It's hard to tell without exception and stack trace, but I assume you need to read TargetType first and not try to create it, like this:

(TargetType) page.Session.GetObject(t.Id)
0
On

It might be that the URIs you use are not from the same Publication context and are therefore invalid.