views:

11705

answers:

10

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.

A: 

Have you recycled your worker process or reset IIS?

Keith Sirmons
I'll give it a try. I hadn't.
Nope... didn't work. Same error and same log file entry.
+7  A: 

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"&gt;
    <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.

Oh, and if this helps you... please up vote it so that I earn my little badge and some rep.

A: 

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 .

Smxyhd
A: 

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.

A: 

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

A: 

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()
    {
    }
+2  A: 

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.

Kirk Liemohn
A: 

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.

Marlobello
A: 

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 waisted time.

SWB

Shannon Bray
A: 

It worked in mine when I transferred the code from the constructor to OnInit() Thanks a lot Kirk L.

EdreX