locked
Hello World == Hello Frustration!! RRS feed

  • Question

  •  

    I have an assembly... it has 3 web parts in it and they work wonderfully.  I am using WSS 3.0, Server 2003, VS 2005, and the SP tools for VS (so i can do the right-click deploy thingy while developing).

     

    Here's the challenge: add a 4th web part.  So I write the following code:

    Code Snippet

     

    using System;
    using System.Runtime.InteropServices;
    using System.Collections.Generic;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using System.ComponentModel;

    namespace Broken.WebParts
    {
      [Guid("797596FC-38E3-4c46-9A2D-FAD8E64BFFE8")]
      class BrokenWebPart : System.Web.UI.WebControls.WebParts.WebPart
      {

        protected override void RenderContents(HtmlTextWriter writer)
        {
          writer.Write(@"Hello stinker");
        }
      }
    }

     

     

    Build the solution, right-click and hit deploy.  The new web part shows up in the Web Part Gallery along with the other ones.  All the other parts continue to work as expected.. however when i click on the new part i get an error:

     

    Code Snippet

    Cannot import BrokenWebPart 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.WebPartPreview.get_WebPart()
       at Microsoft.SharePoint.WebPartPages.WebPartPreview.CreateChildControls()
       at System.Web.UI.Control.EnsureChildControls()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

     

    I dont know how to make it any simpler... and since the error is very generic and doesnt involve any of my code I have no clue how to fix this or where to look for the problem.  

    Thursday, April 3, 2008 8:33 PM

Answers

  • Jez,

     

    Just a quick observation. Your webpart code in the first post shows the BrokenWebPart as not public

     

    Code Snippet

     

    class BrokenWebPart : System.Web.UI.WebControls.WebParts.WebPart

     

     

     

    This would probably cause the error message you appear to be getting...

     

    Cannot import BrokenWebPart Web Part.   at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean clearConnections)

     

    HTH, Vince

    http://blog.thekid.me.uk

     

    Friday, April 4, 2008 9:58 PM

All replies

  • use Render method and it will work. you are using RenderContent which has a different purpose to render contents of a control. since you are simply tryint to write hello world, you should use Render Method.

     

     

     

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        writer.Write("Hello world");
    }

     

     

    Thursday, April 3, 2008 8:53 PM
  •  

    changed it to render and still doesnt work. 

     

    Thursday, April 3, 2008 9:07 PM
  • Are you refering the project templates for Visual Studio?  If so you should not use these.  There are knows issues.  Look into something like Tedd Pattison's stsdev http://www.codeplex.com/stsdev, which is widely used.  If you are looking to do remote deployment try SPDeploy: http://www.ascentium.com/blog/sp/Post29.aspx.
    Thursday, April 3, 2008 10:01 PM

  • yes i am using the project templates.  I check out stsdev and see if it helps.
    Friday, April 4, 2008 3:05 PM
  • Can you post your manifest.xml, feature.xml, webpartName.xml and webpartName.webpart?

    I'm curious to find out what broke.

     

    Also, are you using the 1.1 extensions released 3/6/2008?

    http://www.microsoft.com/downloads/details.aspx?FamilyID=3e1dcccd-1cca-433a-bb4d-97b96bf7ab63&DisplayLang=en

     

     

     

    Friday, April 4, 2008 3:53 PM
  • i will post those for you for sure.  I just ran a repair on WSS (cause i actually think its my wss thats screwed) and then after i did that windows update showed SP1 for wss so i installed that as well.  I am going to try again now with all this done and see if it helps.  If it doesnt i'll come back and post the xml files...

     

    I havent installed any extensions or anything on my box unless they come auto with windows update... especially not anything as recent as 3/8.

    Friday, April 4, 2008 4:11 PM
  • ok so it must be my WSS that is completely fubar.  Even using stsdev this doesnt work.  Using the out of the box example it installs the feature just fine, i can activate it just fine... but going to the web part galery and clicking on one of the parts results in the same old useless error message i was getting before... so i dont think this has anything to do with the xml files or even the parts themselves... i have no clue how to fix it... i suppose i just have to completely remove WSS and hope that a re-install fixes something.

     

    i am gonna try and test this out on another box and see what that gets me...

    Friday, April 4, 2008 6:47 PM
  •  

    so the other machine didnt work either... im baffled.
    Friday, April 4, 2008 7:12 PM
  • plaease share some of the information Micheal requested in earlier post.

     

    Friday, April 4, 2008 7:17 PM
  • Ok here you go... its basically whatever stsdev generates.... i pulled all these from the wsp file:

    Manifest.xml

    Code Snippet

    <?xml version="1.0" encoding="utf-8"?>

    <!--Manifest created STSDEV utility at 4/4/2008 2:12:08 PM-->

    <Solution SolutionId="3C4173A9-FA1B-4E18-8E4C-C412318B5557" ResetWebServer="True" xmlns="http://schemas.microsoft.com/sharepoint/">

    <!--Feature Manifest files-->

    <FeatureManifests>

    <FeatureManifest Location="BrokenWebParts\feature.xml" />

    </FeatureManifests>

    <!--TEMPLATE files-->

    <TemplateFiles>

    <TemplateFile Location="IMAGES\BrokenWebParts\AfricanPith32.gif" />

    </TemplateFiles>

    <!--Assembly files-->

    <Assemblies>

    <Assembly Location="BrokenWebParts.dll" DeploymentTarget="GlobalAssemblyCache">

    <SafeControls>

    <SafeControl Assembly="BrokenWebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b2440d664d82f6d6" Namespace="BrokenWebParts" TypeName="*" Safe="True" />

    </SafeControls>

    </Assembly>

    </Assemblies>

    </Solution>

     

    Feature.xml

    Code Snippet

    <?xml version="1.0" encoding="utf-8"?>

    <!--Created by STSDEV at 4/4/2008 2:11:06 PM-->

    <Feature

    Id="15227B6C-24DD-46ED-8B6F-CA7A35D7A62A"

    Title="A sample feature: BrokenWebParts"

    Description="This SharePoint solution was created by the STSDEV utility (http://codeplex.com/stsdev)"

    Version="1.0.0.0"

    Scope="Site"

    Hidden="false"

    ImageUrl="BrokenWebParts\AfricanPith32.gif" xmlns="http://schemas.microsoft.com/sharepoint/">

    <ElementManifests>

    <ElementManifest

    Location="WebParts.xml" />

    <ElementFile

    Location="WebParts\CustomWebPart1.webpart" />

    <ElementFile

    Location="WebParts\CustomWebPart2.webpart" />

    </ElementManifests>

    </Feature>

     

    WebParts.xml

    Code Snippet

    <?xml version="1.0" encoding="utf-8"?>

    <!--Created by STSDEV at 4/4/2008 2:11:06 PM-->

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">

    <Module Name="BrokenWebParts" List="113" Url="_catalogs/wp" Path="WebParts" RootWebOnly="True">

    <File Url="CustomWebPart1.webpart" Type="GhostableInLibrary">

    <Property Name="Group" Value="BrokenWebParts" />

    </File>

    <File Url="CustomWebPart2.webpart" Type="GhostableInLibrary">

    <Property Name="Group" Value="BrokenWebParts" />

    </File>

    </Module>

    </Elements>

     

    CustomWebPart1.webpart

    Code Snippet

    <?xml version="1.0" encoding="utf-8"?>

    <!--Created by STSDEV at 4/4/2008 2:11:06 PM-->

    <webParts>

    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">

    <metaData>

    <type name="BrokenWebParts.CustomWebPart1, BrokenWebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b2440d664d82f6d6" />

    <importErrorMessage>Error importing Web Part</importErrorMessage>

    </metaData>

    <data>

    <properties>

    <property name="Title" type="string">Default title for CustomWebPart1</property>

    <property name="Description" type="string">A demo Web Part created by stsdev</property>

    <property name="ChromeState" type="chromestate">Normal</property>

    <property name="AllowZoneChange" type="bool">True</property>

    <property name="AllowHide" type="bool">True</property>

    <property name="ExportMode" type="exportmode">All</property>

    </properties>

    </data>

    </webPart>

    </webParts>

     

     

    CustomWebPart2.webpart

    Code Snippet

    <?xml version="1.0" encoding="utf-8"?>

    <!--Created by STSDEV at 4/4/2008 2:11:06 PM-->

    <webParts>

    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">

    <metaData>

    <type name="BrokenWebParts.CustomWebPart2, BrokenWebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b2440d664d82f6d6" />

    <importErrorMessage>Error importing Web Part</importErrorMessage>

    </metaData>

    <data>

    <properties>

    <property name="Title" type="string">Default title for CustomWebPart2</property>

    <property name="Description" type="string">A demo Web Part created by stsdev</property>

    <property name="ChromeState" type="chromestate">Normal</property>

    <property name="AllowZoneChange" type="bool">True</property>

    <property name="AllowHide" type="bool">True</property>

    <property name="ExportMode" type="exportmode">All</property>

    </properties>

    </data>

    </webPart>

    </webParts>

     

    Friday, April 4, 2008 7:30 PM
  • this may also be pertinent info:

    I am running my wss @ http://localhost:7777

    I am running the app pool as a domain user

    I am running the site with only integrated windows auth turned on

    Friday, April 4, 2008 7:34 PM
  •  

    on a brand new server with a fresh install of everything the wsp installs and runs fine... so its got to be my WSS which is screwed up somehow... no clue how or what happened though.

     

     

    Friday, April 4, 2008 9:14 PM
  • Jez,

     

    Just a quick observation. Your webpart code in the first post shows the BrokenWebPart as not public

     

    Code Snippet

     

    class BrokenWebPart : System.Web.UI.WebControls.WebParts.WebPart

     

     

     

    This would probably cause the error message you appear to be getting...

     

    Cannot import BrokenWebPart Web Part.   at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean clearConnections)

     

    HTH, Vince

    http://blog.thekid.me.uk

     

    Friday, April 4, 2008 9:58 PM
  • good catch. person who posted this issue did not responded back but the final answer mentioned is correct that Class should have been marked as public.

     

    Tuesday, April 8, 2008 7:03 PM
  • This is a great catch, but when i switched over to STSDEV as suggested i was using their generated sample code and not my own web part anymore (to eliminate coding errors as being a factor)... so the code at the top wasnt relevent anymore in relation to the problem (this is my fault maybe for not posting the new code or being clearer about my using their sample code).

     

    The fact that the exact same wsp failed on my machine that works on a fresh install is what led me to conclude that the problem must be with my wss somehow.  However, your explanation seems to make a lot of sense it and it almost tempts me to try again in hopes that somehow it will work... but i really dont think it will... but im curious enough to try again now...

    Tuesday, April 8, 2008 8:00 PM