SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm getting error when i try to add a crawled property to managed property "contentshidden"

Anyone know why the problem can ben, when i add a mapping to empty mapping property it is ok, but when i add to contentshidden then i get an error:

 IList<CrawledProperty> crawledProperties = new List<CrawledProperty>();
            Schema schema = new Schema(searchServiceApplication);
            ManagedPropertyCollection allManagedPropertiesCollection = schema.AllManagedProperties;

            foreach (Property p in propertiesList)
                foreach (CrawledProperty crawledProperty in schema.QueryCrawledProperties(string.Empty, 1000, Guid.NewGuid(), string.Empty, true))
                    if (crawledProperty.Name.Contains(p.Name) && !allManagedPropertiesCollection.Contains(p.Name))
                        string name = crawledProperty.Name;
                        if (!crawledProperty.Name.Contains("ows"))
                            ManagedProperty managedProperty = allManagedPropertiesCollection.Create(p.Name, ManagedDataType.Text);
                            ManagedProperty hiddenContentManagedProperty = allManagedPropertiesCollection["ContentsHidden"];

                            Mapping mapping = new Mapping(crawledProperty.Propset, crawledProperty.Name, crawledProperty.VariantType, managedProperty.PID);

                            MappingCollection mappingCollection = managedProperty.GetMappings();
                            MappingCollection hiddenContentsMappingCollection = hiddenContentManagedProperty.GetMappings();
                            if (!mappingCollection.Contains(mapping))
                            if (!hiddenContentsMappingCollection.Contains(mapping))


UPDATE: The error that im getting: "The mapping must be to the managed property being set."

Thanks in advance

share|improve this question
You get an exception? Post the exception :-) – Dennis G Jan 10 '12 at 12:33

I suspect this line is the root cause:


You are trying to add a mapping created for one managed property to another managed property. mapping was created for managedProperty and not hiddenContentManagedProperty (see the last parameter):

Mapping mapping = new Mapping(crawledProperty.Propset, crawledProperty.Name, crawledProperty.VariantType, managedProperty.PID);

The solution would be to create a second mapping like this:

Mapping hiddenContentsMapping = new Mapping(crawledProperty.Propset, crawledProperty.Name, crawledProperty.VariantType, hiddenContentManagedProperty.PID);

Then you would add this mapping to the hiddenContentsMappingCollection:

hiddenContentsMappingCollection.Add(hiddenContentsMapping );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.