11

我有一个自己开发的 Web 部件,如果我手动安装 Web 部件就可以了。

但是,当我按照本网站上的说明打包 Web 部件作为指南时: http ://www.theartofsharepoint.com/2007/05/how-to-build-solution-pack-wsp.html

我在日志文件中收到此错误:

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 中得到了该错误,并且几乎没有解释如何解决它。

任何帮助找到解决方案表示赞赏。

4

11 回答 11

8

弄清楚了。

错误消息来自 .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>

问题是原始 .webpart 文件是在安装了 Visual Studio Extensions for WSS 的 32 位系统上创建的。

但是,由于我现在使用的是 64 位计算机,因此 VSEWSS 不可用,并且我相信这会导致上述 GUID 未被替换,因为我没有使用这些部署工具。

用完整的类型名称替换 GUID 是可行的。

因此,如果您遇到来自 importErrorMessage 节点的错误消息,请检查 .webpart 文件中的类型节点是否看起来更像这样(不相关的示例):

<type name="TitleWP.TitleWP, TitleWP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" />

格式为:Class、Namespace、Version、Culture、PublicKey

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

于 2008-09-23T15:49:25.770 回答
6

我们遇到了同样的问题,发现 WebPartImporter 正在调用我们的 Web 部件的构造函数,并且在构造函数中我们正在执行 SPSecurity.RunWithElevatedPrivileges。

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

于 2009-07-09T15:41:59.103 回答
2

所有伟大的建议。我的问题既独特又愚蠢:我已将解决方案部署到第一个 Web 应用程序,但没有部署到第二个。然而,SharePoint 仍然允许我在第二个 Web 应用程序的网站集上激活该功能(不知道为什么)。这意味着第二个 Web 应用程序在此 Web.config 文件中没有安全控制条目(我愚蠢地检查了第一个 Web.config)。

因此,请仔细检查您是否正在查看正确的 Web 应用程序/web.config。

于 2012-02-08T00:57:40.130 回答
1

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

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

所以我尝试在页面中添加一些其他的web部件,一个奇怪的问题出现,其中一些可以添加,一些不能添加。

在我跟踪我的 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()
 {
        .....
            _spWeb = SPContext.Current.Web;
            //It show me a error here when i trace the code
            _spList = _spWeb.Lists[_listName]; 
        .....
 }

现在停下来,我认为这可能是网页初始化顺序问题。AS网页加载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];
          ....
         }

经过我的测试,错误信息没有再次发生..大声笑~~

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

于 2009-01-16T04:48:46.490 回答
1

我已经多次看到这种异常情况,但没有很好的解决方案。

检查您的程序集、命名空间、类名称是否在任何地方都正确。这让我不止一次挂断电话。

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

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

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

这对我有用。祝你好运。

于 2009-08-04T15:50:50.570 回答
0

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

于 2008-09-23T14:23:01.547 回答
0

解决了我的。

我收到了这个错误:

===========================================================================
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)   
===========================================================================

“无法导入 webpart...”

问题是:不匹配的 GUIDS

检查 webpart 类以及 .xml 和 .webpart 类中的 guid 是否相同。

我正在从其他 webparts 源复制粘贴代码。(Codeplex 上的多个文档上传 Wepart)并忘记修复 guid。

于 2009-01-19T07:40:54.650 回答
0

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

于 2009-02-25T14:23:08.460 回答
0

当我创建基类 Web 部件然后从它继承派生类时出现此错误。基类很好,但是当我尝试将派生类添加到与原始帖子相同的错误的网页时,派生类失败。就我而言,我必须在类中添加一个公共修饰符:

public class DerivedWebPart : BaseWebPart

我还在派生类中添加了一个构造函数来调用基类之一 - 尽管我认为你不应该真的需要这个:

    public DerivedWebPart() : base()
    {
    }
于 2009-03-24T15:29:41.380 回答
0

我发现我的第一次没有导入,但是如果我单击“新建”并添加它,它会起作用。

从那里我获取了 XML 的副本并将其保存到我的项目中。之后,Web 部件运行良好。

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

于 2009-11-08T08:37:31.587 回答
0

我遇到了一个与此非常相似的问题,但 Guid 不是问题:我的 webpart 没有将CLSCompliannt属性设置为 false。像这样:

namespace MyNamespace
{

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

    }
}
于 2010-11-20T21:44:08.943 回答