C# SharePoint错误:“;无法导入Web部件“;

C# SharePoint错误:“;无法导入Web部件“;,c#,sharepoint,moss,web-parts,project-server,C#,Sharepoint,Moss,Web Parts,Project Server,我有一个我已经开发的web部件,如果我手动安装该web部件就可以了 但是,当我按照本网站上的说明将web部件打包为指南时: 我在日志文件中发现此错误: 09/23/2008 14:13:03.67 w3wp.exe (0x1B5C) 0x1534 Windows SharePoint Services Web Parts 8l4d Monitorable Error importi

我有一个我已经开发的web部件,如果我手动安装该web部件就可以了

但是,当我按照本网站上的说明将web部件打包为指南时:

我在日志文件中发现此错误:

09/23/2008 14:13:03.67  w3wp.exe (0x1B5C)                           0x1534  Windows SharePoint Services     Web Parts                       8l4d    Monitorable Error importing WebPart. Cannot import Project Filter.   
09/23/2008 14:13:03.67  w3wp.exe (0x1B5C)                           0x1534  Windows SharePoint Services     Web Parts                       89ku    High        Failed to add webpart http%253A%252F%252Fuk64p12%252FPWA%252F%255Fcatalogs%252Fwp%252FProjectFilter%252Ewebpart;Project%2520Filter.  Exception Microsoft.SharePoint.WebPartPages.WebPartPageUserException: Cannot import Project Filter.     at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean clearConnections)     at Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager manager, XmlReader reader, Boolean clearConnections, Uri webPartPageUri, SPWeb spWeb)     at Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager manager, XmlReader reader, Boolean clearConnections, SPWeb spWeb)     at Microsoft.SharePoint.WebPartPages.WebPartQuickAdd.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(...  
09/23/2008 14:13:03.67* w3wp.exe (0x1B5C)                           0x1534  Windows SharePoint Services     Web Parts                       89ku    High        ...String eventArgument)     
相关的位是:

http%253A%252F%252Fuk64p12%252FPWA%252F%255Fcatalogs%252Fwp%252FProjectFilter%252Ewebpart;Project%2520Filter.
Exception Microsoft.SharePoint.WebPartPages.WebPartPageUserException: Cannot import Project Filter.
at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean clearConnections)
at Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager manager, XmlReader reader, Boolean clearConnections, Uri webPartPageUri, SPWeb spWeb)
at Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager manager, XmlReader reader, Boolean clearConnections, SPWeb spWeb)
at Microsoft.SharePoint.WebPartPages.WebPartQuickAdd.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
这伴随着一条相当简洁的错误消息:“无法导入web部件”

我已检查,并且我的.dll已注册为安全的,它位于GAC中,该功能已激活,web部件显示在web部件库中,所有正确的属性都显示已成功读取web部件文件

一切似乎都准备好了,但我从SharePoint那里得到了这个错误和一点关于如何解决它的解释


非常感谢为您找到解决方案提供的任何帮助。

您是否回收了工作进程或重置了IIS?

解决了这个问题

错误消息来自.webpart文件:

<?xml version="1.0" encoding="utf-8"?>
<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <!--
      The following Guid is used as a reference to the web part class, 
      and it will be automatically replaced with actual type name at deployment time.
      -->
      <type name="7F8C4D34-6311-4f22-87B4-A221FA8735BA" />
      <importErrorMessage>Cannot import Project Filter.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="Title" type="string">Project Filter</property>
        <property name="Description" type="string">Provides a list of Projects that can be used to Filter other Web Parts.</property>
      </properties>
    </data>
  </webPart>
</webParts>

无法导入项目筛选器。
项目过滤器
提供可用于筛选其他Web部件的项目列表。
问题是原始的.webpart文件是在安装了WSS Visual Studio Extensions的32位系统上创建的

但是,由于我现在在64位机器上,VSEWS不可用,我相信这会导致上面的GUID没有被替换,因为我没有使用这些部署工具

将GUID替换为完整的类型名是有效的

因此,如果您遇到来自importErrorMessage节点的错误消息,请检查.webpart文件中的类型节点是否与以下内容类似(不相关的示例):


其格式如下: 类、命名空间、版本、区域性、公钥


您可以轻松地从与SharePoint实例关联的web.config文件中获取它,因为它将位于安全控件列表中。

现在我得到了类似问题的答案,如下所示:

当我尝试向页面添加新的wep部件时,sharepoint会显示一条错误消息,告诉我--无法导入我的web部件,此错误消息在.webpart文件中定义

所以我尝试在页面中添加一些其他web部件,一个奇怪的问题外观,其中一些可以添加,一些无法添加

在我追踪web部件的代码并对其进行分析后,我发现了原因:

web部件ProjectInfo(我的web部件名称)的旧代码为:

现在停止,我想这可能是网页初始化顺序的问题。当网页加载web部件控件时,首先将运行构造函数ProjectInfo()。实际上,网页还没有完成初始化。到时候

所以我做了一个测试。首先,我在网页上放了一个很好的网页,没关系。然后,我试着将web部件放在刚才无法添加的页面中。~~好啊它正在工作…因为页面已经初始化。完成了

好的!我更正了我的代码:

   namespace ProjectInfo
    ....
     public class ProjectInfo:System.Web.UI.WebControls.WebParts.Web.part
     {
            .....
            private SPWeb _spWeb;
            private SPList _spList;
            private string _listName = "ProjectDocs";
            ......
     }
    public ProjectInfo()
     {
            .....
                //Remove code in constructure function.
                //_spWeb = SPContext.Current.Web;
                //It show me a error here when i trace the code
                //_spList = _spWeb.Lists[_listName]; 
            .....
     }

   protected override void CreateChildControls()
        {
         ....
           base.CreateChildControls();

            _spWeb = SPContext.Current.Web;
            _spList = _spWeb.Lists[_listName];
          ....
         }
在我测试之后,错误消息没有再次出现。。 哈哈~~

希望这个解释能对你有所帮助。

解决了我的问题

我得到了这个错误:

===========================================================================
Error importing WebPart. Cannot import ........ Web Part.
Failed to add webpart 
Exception Microsoft.SharePoint.WebPartPages.WebPartPageUserException: Cannot import ... Web Part.     at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean clearConnections)     at Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager manager, XmlReader reader, Boolean clearConnections, Uri webPartPageUri, SPWeb spWeb)     at Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager manager, XmlReader reader, Boolean clearConnections, SPWeb spWeb)     at Microsoft.SharePoint.WebPartPages.WebPartQuickAdd.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)   
===========================================================================
“无法导入Web部件…”

问题是:不匹配的guid

检查webpart类、.xml和.webpart类中的guid是否相同


我从其他Web部件源复制粘贴代码。(多文档上传到Codeplex上的Wepart)并忘记修复GUID。

当我的web部件引用的GAC中的程序集由不同的强名称密钥文件签名时,我也遇到了此错误。
我在决定更新这些DLL时发现了这一点。在将其插入GAC时,我注意到同一个DLL有两个条目,但它们具有不同的公钥标记

当我创建基类web部件并从中继承派生类时,出现了此错误。基类很好,但当我尝试将其添加到网页时,派生类失败,错误与原始文章相同。在我的例子中,我必须在类中添加一个public修饰符:

public class DerivedWebPart : BaseWebPart
此外,我还在派生类中添加了一个构造函数来调用基类1,尽管我认为您实际上不需要这样做:

    public DerivedWebPart() : base()
    {
    }

我们也遇到了同样的问题,发现web部件的构造函数正被WebPartImporter调用,并且在构造函数中,我们使用提升的权限执行SPSecurity.RunWithElevatedPrivileges


由于某些原因,WebPartImporter无法处理此问题。因此,我们只是将代码从构造函数中移到了OnInit(它真正属于的地方),一切都很好。

我已经多次看到这种异常,但都没有得到很好的解决

检查程序集、命名空间和类名是否处处正确。这让我不止一次挂断了电话

确保您有一个有效的SafeControls条目

确保您的.webpart文件有效(如果可以,让SharePoint为您创建该文件)

如果你绝对肯定一切都是正确的,那么你就被困在我去过好几次的地方。我唯一能想到的是VS编译程序集是错误的。我发现的唯一修复方法是创建一个新的VS项目,并根据需要进行设置,然后将旧CS文件的文本复制到新CS文件中…不要复制文件本身…目标是让所有内容都保持新鲜


这对我很有效。祝你好运。

我发现我的不是第一次导入的,但是如果我单击“新建”并添加它,它就会工作

从那里我抓取了一份XML副本并将其保存到我的项目中。在那之后,web部件工作得很好


我只花了几天时间就达到了这一点。浪费了很多时间。

我遇到了一个与此非常类似的问题,但GUID不是问题所在:我的Web部件没有将
CLSCompliannt
属性设置为false。像这样:

namespace MyNamespace
{

    [CLSCompliant(false)]
    [Guid("...")]
    public class MyWidget : MyWebPartBaseClass
    {

    }
}

所有伟大的建议。我的问题是独特而愚蠢的:我将解决方案部署到了第一个Web应用程序,但没有部署到sec
    public DerivedWebPart() : base()
    {
    }
namespace MyNamespace
{

    [CLSCompliant(false)]
    [Guid("...")]
    public class MyWidget : MyWebPartBaseClass
    {

    }
}