为什么我得到,"Error 392 Error occurred in deployment step 'Activate Features': Operation is not valid due to the current state of the object."

Why am I getting, "Error 392 Error occurred in deployment step 'Activate Features': Operation is not valid due to the current state of the object."

Elements.xml 文件中缺少 "Module" 部分是否会导致 "Error 392 Error occurred in deployment step 'Activate Features': Operation is not valid due to the current state of the object."?

我在尝试重建 Sharepoint Web 部件时突然遇到该错误。 One thing I researched 表示可能 Elements.xml 有问题。很长一段时间我没有改变任何东西,我也没有明确改变任何东西,我不认为,但这里是现在的样子:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="104">
      <Receiver>
        <Name>PostTravelItemEventReceiverItemAdded</Name>
        <Type>ItemAdded</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>PostTravelWizard.PostTravelItemEventReceiver.PostTravelItemEventReceiver</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
      <Receiver>
        <Name>PostTravelItemEventReceiverContextEvent</Name>
        <Type>ContextEvent</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>PostTravelWizard.PostTravelItemEventReceiver.PostTravelItemEventReceiver</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>

  </Receivers>
</Elements>

所以它现在只有对我添加的两个 "Event Receiver" 处理程序的引用;我将这个非工作项目的 Elements.xml 文件与我拥有的其他 Elements.xml 文件(来自工作的 Web 部件)进行了比较;其中一个看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
  <Module Name="TravelFormHelpWebPart" List="113" Url="_catalogs/wp">
    <File Path="TravelFormHelpWebPart\TravelFormHelpWebPart.webpart" Url="TravelFormHelpWebPart.webpart" Type="GhostableInLibrary" >
      <Property Name="Group" Value="Financial Affairs Forms" />
    </File>
  </Module>
</Elements>

...还有一个很像,像这样:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
  <Module Name="DPSVisualWebPart" List="113" Url="_catalogs/wp">
    <File Path="DPSVisualWebPart\DPSVisualWebPart.webpart" Url="DPSVisualWebPart.webpart" Type="GhostableInLibrary" >
      <Property Name="Group" Value="Financial Affairs Forms" />
    </File>
  </Module>
</Elements>

区别似乎是工作的 Web 应用程序在其 Elements.xml 文件中有一个 "Module" 部分

从上面的 link 中还有另外一条线索,即:

如果第 2 步没有解决您的错误,请检查您的部署目标是否设置为 "WebApplication"。需要改为"Global AssemblyCache"。

...在这里,同样,不知何故,这个非工作 WebPart 被设置为 "WebApplication,",而其他的被设置为 "GAC")。但是,更改它并没有帮助 - 我仍然收到与上面报告的相同的错误消息。

因此,如果缺少的 "Module" 部分是问题所在,那显然是早些时候存在的(当它工作时)并且以某种方式达到了 86'(随着项目的 "Assembly Deployment Target" 属性,显然)。为什么 would/how 会发生这种情况?

添加(返回,显然)模块部分成功了。

具体来说,我在 "Receivers" 部分上方添加了以下内容:

<Module Name="PostTravelWizardWebPart" List="113" Url="_catalogs/wp">
    <File Path="PostTravelWizardWebPart\PostTravelWizardWebPart.webpart" Url="PostTravelWizardWebPart.webpart" Type="GhostableInLibrary" >
      <Property Name="Group" Value="Financial Affairs Forms" />
    </File>
</Module>

...现在部署成功。

(请注意,我也将项目的 "Assembly Deployment Target" 属性 的值从 "WebApplication"

更改(再次,明显地返回)到 "GlobalAssemblyCache"