Custom Module Error Trying to Publish - Bugs & Issues - Bugs & Issues - Progress Community
 Bugs & Issues

Custom Module Error Trying to Publish

  • Custom Module Error Trying to Publish
  • Hi,

     Alot of this is new to me, so please excuse me if I'm missing something obvious. I'm trying to create a Custom Module of some user profile data. Upon trying to publish the item via the given Sitefinity code (dynamicModuleManager.Lifecycle.Publish(userProfileItem);), I get an error telling me that:

     "Object references between two different object scopes are not allowed. The object 'Telerik.Sitefinity.DynamicTypes.Model.Profiles.UserProfile' is already managed by 'ObjectScopeImpl 0x60 OpenAccessRuntime.EnlistableObjectScope' and was tried to be managed again by 'ObjectScopeImpl 0x67 OpenAccessRuntime.EnlistableObjectScope'."

     

    Does anyone know what this means and/or how to go about resolving it? If I need to include more detail or more of my code, I can gladly do that.

     Thanks!

  • public void PublishUserData(ApplicantFormModel FormData)
        var providerName = "OpenAccessProvider";
     
        DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
        Type userProfileType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Profiles.UserProfile");
        DynamicContent userProfileItem = dynamicModuleManager.CreateDataItem(userProfileType);
              
        // This is how values for the properties are set
        userProfileItem.SetValue("Title", "User profile for " + FormData.FirstName + FormData.LastName);
        userProfileItem.SetValue("FirstName", FormData.FirstName);
        userProfileItem.SetValue("LastName", FormData.LastName);
        userProfileItem.SetValue("KlickID", FormData.APIReturnedID);
        userProfileItem.SetValue("Email", FormData.Email);
        userProfileItem.SetValue("Phone", FormData.Phone);
     
        userProfileItem.SetString("UrlName", "url.com/profile/" + FormData.LastName);
        userProfileItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
        userProfileItem.SetValue("PublicationDate", DateTime.Now);
     
        userProfileItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");
     
        // You need to call SaveChanges() in order for the items to be actually persisted to data store
        dynamicModuleManager.SaveChanges();
     
        // We can now call the following to publish the item
        dynamicModuleManager.Lifecycle.Publish(userProfileItem);
        //You need to set appropriate workflow status
        userProfileItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
        // Now the item is published and can be seen in the page
     
        // You need to call SaveChanges() in order for the items to be actually persisted to data store
        dynamicModuleManager.SaveChanges();
  • Sitefinity uses teleriks OpenAccess (now Data Access) ORM.  So each "Context\Scope" is like a connection or instance of the DB...manages state\etc.

    It might help if you paste in your code?
  • Hello Matt,

    You should not have issues creating an item using the code you have provided. Most probably the problem you are observing is caused by the fact that the object is used in two transactions at the same time. It is really hard to say what might be causing the issue.

    Just for a test can you please try to instantiate the dynamic module manager using the following code:

    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(String.Empty);

    In addition to this, you can find samples on how to work with your dynamic module programatically in the code reference which is automatically generated for your dynamic module created using the Module Builder. To view the generated code samples please go to Administration -> Module builder and select your module. Then please click on the Code reference for <module name> link which is on the right-hand side of the page. Here is a screenshot for your convenience. 

    Regards,
    Sabrie Nedzhip
    Telerik
     
    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
     
  • Hi,

     Thanks for the info. I tried instantiating the dmm using String.Empty as you suggested and I'm still getting the same double scoping error. Any other ideas?

    Thanks!

  • Hello Matt,

    This issue might be caused if you have instantiated a manager and have not saved the changes between two different operations. Thus, the managers works in different scope, which is not allowed in OpenAccess.

    The other reason for the issue might be if you are not authenticated in the thread you wish to update. The dynamicModuleManager.Lifecycle.Publish() method requires authentication. In order to allow anonymous users to create items without the need to authenticate, you can wrap your code (related to creating and saving the item) in: 

    using(new ElevatedModeRegion(dynamicModuleManager))
           // your code goes here

    This elevated mode region will surpass the security checks of the dynamic module manager and allow anonymous users to create items through code.

    Another option would be to set the SuppressSecurityChecks of the manager to true as demonstrated in the following forum post. After you call dynamicModuleManager.SaveChanges();, you may set the SuppressSecurityChecks property of the manager to false.

    Regards,
    Sabrie Nedzhip
    Telerik
     
    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