C# &引用;由于对象的当前状态,操作无效;部署sharepoint事件接收器时
我有一个简单的事件接收器,当我创建一个构造函数时,我在部署步骤中遇到了错误,我仔细检查了feature、Elements.xml文件和我的代码中的事件接收器范围,奇怪的是当我删除构造函数(在这里我使用服务定位器获取我的实现类的实例)时,它工作正常 我的代码是这样的:C# &引用;由于对象的当前状态,操作无效;部署sharepoint事件接收器时,c#,visual-studio-2010,sharepoint,exception,C#,Visual Studio 2010,Sharepoint,Exception,我有一个简单的事件接收器,当我创建一个构造函数时,我在部署步骤中遇到了错误,我仔细检查了feature、Elements.xml文件和我的代码中的事件接收器范围,奇怪的是当我删除构造函数(在这里我使用服务定位器获取我的实现类的实例)时,它工作正常 我的代码是这样的: private INotificationService iNotificationService; public CongeER() { SPSite currentSite = SPCon
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);
}
如果您无法使用SharePoint Alert功能,并且您不需要一个能够以最小的努力发送电子邮件的工作流,则应删除构造函数并将其代码放入ItemAdded方法。您是否尝试从网站用户界面激活该功能?是的,我尝试过,发生以下情况:运行时错误描述:服务器上发生应用程序错误。此应用程序的当前自定义错误设置阻止查看应用程序错误的详细信息。这似乎是新假期的通知。您能告诉我业务场景吗?这样我就可以为您提供符合SharePoint最佳实践的解决方案了?业务场景非常简单:当从web部件或web服务发送休假请求时,我需要向经理发送电子邮件,“iNotificationService”类有各种通知方法,包括发送电子邮件。如果我从构造函数中移动代码,将调用ItemAdded()函数,但我无法从serviceLocator中获取新实例,谢谢您的时间。对象引用未设置为对象的实例。调用堆栈如何?可能是SPSite currentSite=SPContext.Current.Site;谁在从visual studio部署期间导致错误。尝试SPSite site=properties.OpenSite();不,现在它部署正确了,我替换了SPSite currentSite=SPContext.Current.Site;SPSite currentSite=new SPSite(“);但iNotificationService.NotifyByMail()导致了错误,但它不是空的!不管我如何使它工作,后面的问题是由于NotifyByMail()实现错误造成的,您知道这周已经结束了,非常感谢陛下。
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...