Posted by: tchmiel | August 9, 2010

Activate Feature error – Custom Content Types when debugging from Visual Studio 2010

Problem Statement

When creating a custom content type, derived from the Document Content Type with one additional text field, using Visual Studio 2010 and deploying via F5, the first time deployment will work fine, second time failed with this error:

Error occurred in deployment step ‘Activate Features’: The field with Id {a6a841d7-4067-4519-b794-e25ac438e9cf} defined in feature {a6192d76-512f-48de-9284-251b49902345} was found in the current site collection or in a subsite.

 Microsoft has acknowledged this as a problem, and is working on a fix.

 Workaround

 To workaround this problem and to continue to enjoy your Visual Studio 2010 debugging experience, you will need to follow these steps.

1. F5 (Deploy the solution)

2. Shift +F5 (Retract the solution)

3. Again F5. This time it will fail.

4. Open the task manager and kill VSSPHost4 process.

(Ideally we need to kill the VSSPHost4 process any time you see the error message during the F5 deployment.)

To make it easier on myself, I kill the VSSPHost4 process from an SharePoint 2010 Management Shell, run as Administrator, like this:

stop-process -processname vssphost4 -force

5. Now F5 and the solution will get deployed successfully.

 You could also avoid this error, but installing and deploying the feature outside the Visual Studio 2010 debugger, either thru STSADM or thru PowerShell!

Hope this saves you some time.

Tom

 
 

Details on How to Reproduce, if you care.

 
 

  1. In Visual Studio 2010, create a new “ContentType” project,

     
     


 
 

  1. Specify the site and solution type.

    The site should be a site collection, not a subsite.

    The solution should be a farm solution.

  2. Inherit this new content Type from the Base Content Type of “Document”
  3. Replace the contents of Elements.xml with this contents:

     
     

    <?xml version=”1.0″ encoding=”utf-8″?>

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

    <!– Parent ContentType: Document (0x0101) –>

     
     

    <Field ID=”{D6A841D7-4067-4519-B794-E25AC438E9CF}”

    Name=”MyCustomField”

    StaticName=”MyCustomField”

    DisplayName=”MyCustomField”

    Description=”MyCustomField”

    Group=”abc”

    Type=”Text”

    SourceID=”http://schemas.microsoft.com/sharepoint/v3” />

     
     

    <ContentType ID=”0x010100b19e17b94ee044778dcffe8f92ce18e6″

    Name=”ContentTypeProject2 – ContentType1″

    Group=”Custom Content Types”

    Description=”My Content Type”

    Inherits=”TRUE”

    Version=”0″>

    <FieldRefs>

    <FieldRef ID=”{D6A841D7-4067-4519-B794-E25AC438E9CF}” Name=”MyCustomField”/>

    </FieldRefs>

    </ContentType>

    </Elements>

     
     

  4. Hit F5 to compile and deploy this Content Type.

 
 

  1. After the SharePoint site is displayed, verify the content type exists.

 
 

  1. Back in VS2010, hit Shift-F5 to stop debugging.

     
     

  2. Hit F5 to redeploy this Content type and it will fail with the following error:

 
 

Error occurred in deployment step ‘Activate Features’: The field with Id {a6a841d7-4067-4519-b794-e25ac438e9cf} defined in feature {a6192d76-512f-48de-9284-251b49902345} was found in the current site collection or in a subsite.

 
 

  1. Now edit the elements.xml file, by changing the GUID, and set the Overwrite attribute to TRUE, you will not be able to deploy and reploy over and over again.

     
     

    <?xml version=”1.0″ encoding=”utf-8″?>

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

    <!– Parent ContentType: Document (0x0101) –>

     
     

    <Field ID=”{A6A841D8-4067-4519-B794-E25AC438E9CF}”

    Name=”MyCustomField”

    StaticName=”MyCustomField”

    DisplayName=”MyCustomField”

    Description=”MyCustomField”

    Group=”abc”

    Type=”Text”


    Overwrite =”TRUE”

    SourceID=”http://schemas.microsoft.com/sharepoint/v3” />

     
     

    <ContentType ID=”0x010100b19e17b94ee044778dcffe8f92ce18e6″

    Name=”ContentTypeProject2 – ContentType1″

    Group=”Custom Content Types”

    Description=”My Content Type”

    Inherits=”TRUE”

    Version=”0″>

    <FieldRefs>

    <FieldRef ID=”{A6A841D8-4067-4519-B794-E25AC438E9CF}” Name=”MyCustomField”/>

    </FieldRefs>

    </ContentType>

    </Elements>

Advertisements

Responses

  1. Here is a link to the Chandraseker’s post that describes the problem in a little more detail. http://blogs.msdn.com/b/chandru/rss.aspx

  2. thanks for this information. Nothing like a ‘feature’ in new code. On a different note, I am seeing a problem, now where I cant delete a content type at all. Says it is part of a feature, but the original feature is gone (both uninstalled, and folder removed).
    rs

    • Saw this issue once or twice before. Have you tried to recurse the sitecollection/webs via powershell to see if something is hanging around? Or check for the error in the log file, maybe it has more specific information? If you don’t see it anywhere, you may have to delete the site collection and recreate it. I did this once or twice before I set the OVERWRITE attribute to TRUE. After I see this attribute, I don’t remember getting this feature still exists.

  3. Thanks for the information I was tearing my hear out for about an hour with this, your solution saved me a lot of grief.

  4. Thanks for you tip. It helped me lot.

  5. I never write comments on blogs. But this really worked for me. Thanks alot

  6. Glad I could help you out here, and appreciate the comment letting me the fruits of writing a blog are not being wasted. I tend to only blog stuff that I, myself, have suffered thru and can’t easily be found elsewhere on the web.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Categories

%d bloggers like this: