More in this section
Forums / Developing with Sitefinity / LibrariesManager.Lifecycle.GetLive returns null even though the document is published

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

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 0 answered
  1. Jacques
    Jacques avatar
    427 posts
    28 Jun 2007
    20 Apr 2016
    Link to this post

    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? 

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    06 Sep 2017
    25 Apr 2016
    Link to this post
    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
  3. Robert
    Robert avatar
    2 posts
    07 Mar 2014
    15 Jun 2017
    Link to this post

    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? 

3 posts, 0 answered