SharePoint 错误:“无法导入 Web 部件”

发布于 2024-07-05 03:10:14 字数 2655 浏览 7 评论 0原文

我有一个我开发的 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 几乎没有解释如何解决该错误。

任何寻求解决方案的帮助都将受到赞赏。

I have a web part that I've developed, and if I manually install the web part it is fine.

However when I have packaged the web part following the instructions on this web site as a guide:
http://www.theartofsharepoint.com/2007/05/how-to-build-solution-pack-wsp.html

I get this error in the log files:

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)     

The pertinent bit is:

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)

And that's accompanied by a rather terse error message: "Cannot import web part".

I have checked and my .dll is registered as safe, it is in the GAC, the feature is activated, and the web parts appear in the web part library with all of the correct properties showing that the webpart files were read successfully.

Everything appears to be in place, yet I get that error and little explanation from SharePoint of how to resolve it.

Any help finding a solution is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

2024-07-12 03:10:15

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

检查您的程序集、命名空间、类名是否正确。 这已经让我不止一次挂断了。

确保您有有效的 SafeControls 条目。

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

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

这对我有用。 祝你好运。

I have seen this anomaly several times without a good resolution.

Check that your Assembly, Namespace, Class name is correct EVERYWHERE. This has hung me up more than once.

Make sure you have a valid SafeControls entry.

Make sure your .webpart file is valid (let SharePoint create it for you if you can)

If you are absolutely positive that everything is correct, well then you are stuck in a place that I have been several times. The only thing that I can come up with is that VS is compiling the assembly wrong. The ONLY fix that I have found is to create a new VS project and set it up how you need, then copy THE TEXT of your old CS files into your new CS files...do not copy the files themselves...the goal is to have everything fresh.

This has worked for me. Good Luck.

水溶 2024-07-12 03:10:15

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

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

All great suggestions. My problem was unique and silly: I had deployed the solution to the first Web Application but not to the second. SharePoint however still allowed me to activate the feature on the second Web App's Site Collection (not sure why). This meant the second Web App didn't have a safe control entry in this Web.config file (and I was stupidly checking the first Web.config).

So, double-check you're looking at the correct web application/web.config.

知足的幸福 2024-07-12 03:10:15

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

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

We had this same problem and found that the constructor of our web part was being called by the WebPartImporter and within the constructor we were doing SPSecurity.RunWithElevatedPrivileges.

For some reason the WebPartImporter cannot handle this. So, we simply moved our code out of the constructor to OnInit (where it really belonged) and all is well.

终遇你 2024-07-12 03:10:15

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

namespace MyNamespace
{

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

    }
}

I had a problem very similar to this, but Guids weren't the problem: my webpart didn't have the CLSCompliannt attribute set to false. Like so:

namespace MyNamespace
{

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

    }
}
空城之時有危險 2024-07-12 03:10:15

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

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

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

I found that mine did not import the first time, but if I clicked 'New' and added it, it would work.

From there I grabbed a copy of the XML and saved it to my project. The web part worked great after that.

It only took me DAYS to get to this point. A lot of wasted time.

请恋爱 2024-07-12 03:10:15

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

public class DerivedWebPart : BaseWebPart

此外,我还在派生类中添加了一个构造函数来调用基类 - 尽管我认为您实际上不应该需要这个:

    public DerivedWebPart() : base()
    {
    }

I got this error when I created a base class web part and then inherited a derived class from it. The base class was fine but the derived class failed when I tried to add it to a web page with the same error as the original post. In my case I had to add a public modifier to the class:

public class DerivedWebPart : BaseWebPart

Also I added a constructor in the derived class to call the base class one - although I think you shouldn't need this really:

    public DerivedWebPart() : base()
    {
    }
陌伤浅笑 2024-07-12 03:10:15

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

当我尝试向页面添加新的 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]; 
        .....
 }

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

测试后,错误消息不再出现。
哈哈~~

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

Now I get a answer for similar problem as below:

When I try to added a new wep part to the page, then sharepoint show me a error message, tell me--Can not import my web part, this error message define in .webpart file.

So i tried to add some ohter web parts in the page , A strange quesiton appearance, some of them can be added , some of them can not be added.

After I traced the code of my web part and anaylsis them, I found the reason:

Old Code for web part ProjectInfo(my web part name) is:

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]; 
        .....
 }

Stop now, I thought that it maybe the web page init order problem. AS web page load web part control, constructrue function ProjectInfo() will be running at first. Actually, the web page havn't finish its init. by the time.

so i did a test. firstly, I put a good web in the page, it's ok . then, I try to put the web part in the page which can not be added just now. ~~ OK!! It's working ...because the page already init. finished.

Ok! I corrected my code:

   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];
          ....
         }

After I test, the error message did't happed again..
LoL ~~

Hope this explain will help you .

月牙弯弯 2024-07-12 03:10:15

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

I have also experienced this error when the assemblies in the GAC that my web part referenced, was signed by a different strong name key file to what I was expecting.
I found this out when deciding to update these DLLs. When inserting it into the GAC I noticed that there were 2 entries for the same DLL but they had different Public Key Tokens

弥枳 2024-07-12 03:10:15

解决了我的。

我收到此错误:

===========================================================================
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...”

问题是:不匹配的 GUID

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

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

Solved mine.

i was getting this error:

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

"Cannot import webpart..."

The problem was: Non-matching GUIDS

Check if the guid on webpart class , and in the .xml and in .webpart class are same.

I was copy-pasting code from other webparts sources. ( Mutliple Document Upload Wepart on Codeplex) and forgot to fix guids.

关于从前 2024-07-12 03:10:15

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

Have you recycled your worker process or reset IIS?

装纯掩盖桑 2024-07-12 03:10:14

弄清楚了。

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

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

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

Figured it out.

The error message is the one from the .webpart file:

<?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>

The problem is that the original .webpart file was created on a 32-bit system with Visual Studio Extensions for WSS installed.

However as I'm now on a 64-bit machine VSEWSS is unavailable, and I believe that results in the above GUID not being substituted as I am not using those deployment tools.

Replacing the GUID with the full type name works.

So if you encounter the error message from your importErrorMessage node, then check that your type node in the .webpart file looks more like this (unrelated example):

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

This is in the format:
Class, Namespace, Version, Culture, PublicKey

You can grab that easily from the web.config file associated with your SharePoint instance, as it will be in the safe controls list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文