";由于对象“”的当前状态,操作无效;当部署sharepoint事件接收器时

本文关键字:操作 状态 无效 sharepoint 接收器 事件 部署 于对象 quot 对象 | 更新日期: 2023-09-27 18:25:07

我有一个简单的事件接收器,当我创建一个构造函数时,我在部署步骤中遇到了错误,我仔细检查了feature、Elements.xml文件和我的代码中的事件接收器范围,奇怪的是,当我删除构造函数(我使用服务定位器来获取实现类的实例)时,它运行良好。

我的代码是这样的:

    private INotificationService iNotificationService;
    public CongeER()
    {
        SPSite currentSite = SPContext.Current.Site;
        IServiceLocator locator = SharePointServiceLocator.GetCurrent(currentSite);
        try
        {
            iNotificationService = locator.GetInstance<INotificationService>();
        }
        catch (System.Exception ex)
        {
            System.Console.WriteLine(ex.Message);
        }
    }
   public override void ItemAdded(SPItemEventProperties properties)
   {
       iNotificationService.NotifyByMail();
       base.ItemAdded(properties);
   }

这是我的堆栈跟踪:

  Feature Activation: Threw an exception, attempting to roll back.
  Exception: System.InvalidOperationException: 
  L'opération n'est pas valide en raison de l'état actuel de l'objet.     
  à Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionContentTypeAndEventReceiverBindings(SPFeaturePropertyCollection props, SPSite site, SPWeb web, Boolean fForce)     
  à Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, Boolean fForce)     
  à Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, Boo...

";由于对象“”的当前状态,操作无效;当部署sharepoint事件接收器时

如果您不能使用SharePoint Alert功能,并且您不需要一个也可以用最少的精力发送电子邮件的工作流,那么您应该删除构造函数并将其代码放入ItemAdded方法中。

相关文章: