A short note on another EPiServer exception that I encountered today while trying to save a newly created EPiServer page programmatically from codebehind. The reason for it is rather self explaining looking back at it.
var page = _contentRepository.GetDefault<ArticlePage>(parentReference, languageSelector); // Do stuff _contentRepository.Save(page, SaveAction.Publish | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);
It’s not possible to force the current version as it does not exist yet, Doh.. So just finding myself content with only doing what is neccessary fixed the problem right up.
_contentRepository.Save(page, SaveAction.Publish, AccessLevel.NoAccess);
And the exception for searchability.
System.Data.SqlClient.SqlException (0x80131904): editSaveContentVersionData: The WorkContentId dosen´t exist (WorkContentID=0) at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser .ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand .InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at EPiServer.DataAccess.ContentSaveDB.SaveContentVersionData(IContent content, Boolean isNew, Boolean delayPublish, String currentUser) at EPiServer.DataAccess.ContentSaveDB.CreateAndSave(IContent content, Boolean delayPublish, Boolean forceCurrentVersion, Boolean forceNewVersion, String currentUser) at EPiServer.DataAccess.ContentSaveDB.<>c__DisplayClass16.<SaveInternal>b__15() at EPiServer.Data.Providers.SqlDatabaseHandler.<>c__DisplayClass4.<ExecuteTransaction>b__3() at EPiServer.Data.Providers.SqlDatabaseHandler.<>c__DisplayClass7`1.<ExecuteTransaction>b__6() at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy .Execute[TResult](Func`1 method) at EPiServer.DataAccess.ContentSaveDB.SaveInternal(IContent content, SaveAction action, Nullable`1 delayPublishUntil, String currentUser) at EPiServer.DataAccess.ContentSaveDB.Save(IContent content, SaveAction action, String currentUser) at EPiServer.DataAbstraction.ContentStore.Save(IContent content, SaveAction action, String currentUser) at EPiServer.DefaultContentProvider.Save(IContent content, SaveAction action) at EPiServer.Core.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access)