0

I'm using event receivers to modify some of the inputs in a SharePoint 2013 site.

They are fairly straight forward, here is a simple example

public override void ItemAdded(SPItemEventProperties properties)
{
    base.ItemAdded(properties);

    using (SPSite site = new SPSite(properties.WebUrl))
    {
        using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
        {
            //web.AllowUnsafeUpdates = true;
            SPListItem item = properties.ListItem; // Boom!
            var title = item["Title"].ToString();
            item["Title"] = title.Replace(" ", "_");

            //item.Update();
            //item.SystemUpdate(false);
        }
    }
}

This renders the error

Message:
    Method not found: 'Microsoft.BusinessData.Runtime.IEntityInstance Microsoft.BusinessData.Runtime.NotificationParser.GetChangedEntityInstance(Microsoft.BusinessData.MetadataModel.IEntity, Microsoft.BusinessData.MetadataModel.ILobSystemInstance)'.

Source:
    Microsoft.SharePoint

StackTrace:
   at Microsoft.SharePoint.SPItemEventProperties.get_ListItem()
   at eventreceivers.Kundregister.PrivateCustomer.PrivateCustomer.<>c__DisplayClass2.<ItemAdded>b__0()
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.<RunWithElevatedPrivileges>b__3()
   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)

I have ensured that those methods are available in the class.

Any advices are highly appreciated, thanks!

Eric Herlitz
  • 25,354
  • 27
  • 113
  • 157

1 Answers1

2

I was already facing the same issue.

instead of using

SPListItem item = properties.ListItem; 

use following code to get item,

SPListItem item = properties.Web.Lists.TryGetList(properties.ListTitle).GetItemById(properties.ListItemId);

All the best!

Regards, Praveen Singh

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Praveen
  • 21
  • 3