LibrariesManager.Lifecycle.GetLive returns null even though

Posted by Community Admin on 04-Aug-2018 20:07

LibrariesManager.Lifecycle.GetLive returns null even though the document is published

All Replies

Posted by Community Admin on 20-Apr-2016 00:00

I'm trying to extract the URL for a published document in a custom widget built in an external project. 

The code is as follows: 

01.if (LinkToTermsAndConditions != Guid.Empty)
03.    var doc = Telerik.Sitefinity.App.WorkWith().Document(documentGuid).GetLive().Get() as Telerik.Sitefinity.Libraries.Model.Document;
04.    //LibrariesManager librariesManager = new LibrariesManager();
05.    //var document = librariesManager.GetDocuments().Where(d => d.Id == documentGuid).FirstOrDefault();
07.    //if (document != null)
08.    //
09.    //    document = librariesManager.Lifecycle.GetLive(document) as Telerik.Sitefinity.Libraries.Model.Document;
10.    //
12.    TermsAndCondtions.HRef = doc.Url;

I've tried both the Fluent and normal approaches and in both cases if I just get the document, it retrieves it successfully but as soon as I try to get the current live version, it returns null. 

In line 3 above, the Fluent version, I get an exception "An exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll but was not handled in user code"

However when I run: 


I get a document URL.

I've confirmed that the document, a PDF, is definitely published. 

Why does the call to Lifecycle.GetLive always return null? 

Posted by Community Admin on 25-Apr-2016 00:00

Hello Jacques,

How the Id of the document is get? Testing the sample from that article:, seems working fine with both APIs using the following code:
Native API:

private Document GetDocumentNativeAPI(Guid masterDocumentId)
    LibrariesManager librariesManager = LibrariesManager.GetManager();
    Document document = librariesManager.GetDocuments().Where(d => d.Id == masterDocumentId).FirstOrDefault();
    if (document != null)
        document = librariesManager.Lifecycle.GetLive(document) as Document;
    return document;

Fluent API:
private Document GetDocumentFluentAPI(Guid masterDocumentId)
    return App.WorkWith().Document(masterDocumentId).GetLive().Get();

The document is get by:
var libManager = LibrariesManager.GetManager();
var document = libManager.GetDocuments().Where(d => d.Title == "MyDocumentName").FirstOrDefault();
var liveDocFluent = GetDocumentFluentAPI(document.Id);
var liveDocNative = GetDocumentNativeAPI(document.Id);

Svetoslav Manchev
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items

Posted by Community Admin on 15-Jun-2017 00:00

We are experiencing the exact same issue described by Jacques when retrieving DynamicContent items. Consider this code:

Guid id = new Guid("ac5ccbf3-1c23-67bb-b384-ff0000f3621c");
DynamicModuleManager manager = DynamicModuleManager.GetManager( string.Empty );
var master = manager.GetDataItems( "Telerik.Sitefinity.DynamicTypes.Model.Procedures.Procedure" ).Where( i => i.Id == request.Id ).FirstOrDefault();    // returns live, visible item.
var item = manager.Lifecycle.GetLive( master );     // returns null
var masterTwo = manager.GetDataItem( "Telerik.Sitefinity.DynamicTypes.Model.Procedures.Procedure", request.Id );    // returns live, visible item.
var temTwo = manager.Lifecycle.GetLive( masterTwo );    // returns null


As far as I can tell, the master version returned from Sitefinity is the current version---no draft versions were created after the most-recent master version and all of the master item's properties suggest it is the published version---so that leaves us with this ugly workaround:

// If the item is null and the master version is the published version, use the master version.
if ( item == null && master.Id.Equals( id ) && master.Status == ContentLifecycleStatus.Live && master.Visible )
    item = master;


Is there a reason manager.Workflow.GetLive() is not returning the published version of a content item even though one exists? 

This thread is closed