2

I want sharepoint to "persist" a List of object

I wrote a class SPAlert wich inherit from SPPersistedObject :

public class SMSAlert: SPPersistedObject
{
        [Persisted]
        private DateTime _scheduledTime;

        [Persisted]
        private Guid _listId;
        [Persisted]
        private Guid _siteID;
}

Then I wrote a class wich inherit from SPJobDefinition an add a List of my previous object:

public sealed class MyCustomJob: SPJobDefinition
{


        [Persisted]
        private List<SMSAlert> _SMSAlerts;
}

The problem is :

when I call the Update method of y MyCustomJob:

myCustomJob.Update();

It throw an exception :

message :

An object in the SharePoint administrative framework, depends on other objects which do not exist. Ensure that all of the objects dependencies are created and retry this operation.

stack

at Microsoft.SharePoint.Administration.SPConfigurationDatabase.StoreObject(SPPersistedObject obj, Boolean storeClassIfNecessary, Boolean ensure) at Microsoft.SharePoint.Administration.SPConfigurationDatabase.PutObject(SPPersistedObject obj, Boolean ensure) at Microsoft.SharePoint.Administration.SPPersistedObject.Update() at Microsoft.SharePoint.Administration.SPJobDefinition.Update() at Sigi.Common.AlertBySMS.SmsAlertHandler.ScheduleJob(SPWeb web, SPAlertHandlerParams ahp)

inner exception

An object in the SharePoint administrative framework depends on other objects which do not exist.

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Dependencies1_Objects".

The conflict occurred in database "SharePoint_Config, table "dbo.Objects", column 'Id'. The statement has been terminated.

Can anyone help me with that??

Sam
  • 129
  • 2
  • 15

3 Answers3

2

Ensure that your class is marked with a unique GUID, using [System.Runtime.InteropServices.Guid("GUID")] and ensure that the persisted object's class has a default constructor. Hope this help.

Skippy
  • 56
  • 2
2

Both the above suggestions are very important, adding a Guid attribute and ensuring you have a default constructor. Not only for your persisted SMSAlert object, but make sure you have these for your SPJobDefinition as well.

Additionally, if you create collections of SPPersistedObject you have to ensure that each object in the collection is also updated. A better alternative is to make SMSAlert an SPAutoSerializingObject. Collections of SPAutoSerializingObject, as the name implies, are automatically serialized.

For more information on persisted objects see this extremely useful post: http://www.chaholl.com/archive/2011/01/30/the-skinny-on-sppersistedobject-and-the-hierarchical-object-store-in.aspx

Dennis George
  • 1,495
  • 2
  • 10
  • 18
1

Did you specify the default constructor for SMSAlert?

zincorp
  • 3,284
  • 1
  • 15
  • 18
  • No, I didn't do it so I added it and I don't have an exception anymore but when I retreive my "MyCustomJob" the list has the good number of items, but each item is null – Sam Mar 09 '10 at 09:39