1
votes

I have this piece of code below which I am using to publish to the web database. I am having an issue where when I publish with the code below I have a corrupt item in the web database which when I click on gives me the error 'Value cannot be null. Parameter name 'item''. When I look at the item the icon for it is that of the standard template vs the custom template which has a custom icon. But when I click on it I saw all the fields and also the above mentioned error.

Could having an item with the same name as the published item in the web database be an issue?

using (new SecurityDisabler())
{
    Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
    Sitecore.Data.Database target = Sitecore.Configuration.Factory.GetDatabase("web");
    Sitecore.Data.Items.Item home = master.GetItem(new ID(id));
    Sitecore.Data.Database[] targetDatabases = { target };
    Sitecore.Globalization.Language[] languages = master.Languages;
    bool deep = false;
    bool compareRevisions = true;
    Sitecore.Publishing.PublishManager.PublishItem(home, targetDatabases, languages, deep, compareRevisions);
}
1
Can you confirm that the template that the item is based on exists in the 'web' database?Sean Kearney
Yes the template exists. This problem doesn't occur on every publish for every item. It happens for some items only.Gabbar
Does it also occur if you publish it manually from Sitecore (not from code)?Ruud van Falier
No, the manual publishing works fine without any problems.Gabbar
When I go into the web database and hit 'reset' from the presentation tab the item becomes all goodGabbar

1 Answers

1
votes

If related to the context your are publishing in

Async publishing

You could try to run the publishing job asynchronously. The publishing is then done through a Sitecore job.

using Sitecore.Publishing;
PublishOptions publishOptions = new PublishOptions(item.Database, Database.GetDatabase("web"), PublishMode.SingleItem, item.Language, DateTime.Now) { Deep = deep, RootItem = item };

Publisher p = new Publisher(publishOptions);
p.PublishAsync();

If this does not make any difference it could be related to an invalid field value left in the items values table.

Database cleanup

You could try a Database Cleanup and remove old field for a start and if still causing problems You should take a look at the value fields in the database level and compare field values on a "wrong" publish and a correct publish.