I'm trying to get embedded Schema field values in a Template Building Block. The field in question is of type "link to Component" and can be present in the Component multiple times. Therefore, I need to put all the Component IDs in a list, but I plan to do that later. For the moment I have problems accessing the first field found:
string pageURI = package.GetValue("Page.ID");
Page page = (Page)engine.GetSession().GetObject(pageURI);
Component componentA = (Component)engine.GetSession().GetObject(page.ComponentPresentations[0].Component.Id);
var fieldsA = new ItemFields(componentA.Content, componentA.Schema);
// DOES NOT WORK
EmbeddedSchemaField embeddedSlideshare = (EmbeddedSchemaField)fieldsA["slideshare"];
ItemFields embeddedFields = embeddedSlideshare.Value ;
I checked the XML name of my field and there is no error
When I run it with the Template Builder, I get the following stack:
Debugging was started in process 'TcmTemplateDebugHost' with id 209180 The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Tridion.ContentManager.ContentManagement.Fields.ItemFields.get_Item(String fieldName) at Tridion.Templating.CSharpTemplate.CSharpSourceTemplate.Transform(Engine __engine, Package __package) at Tridion.ContentManager.Templating.Assembly.CSharpSourceCodeMediator.Transform(Engine engine, Template template, Package package) at Tridion.ContentManager.Templating.Engine.ExecuteTemplate(Template template, Package package) at Tridion.ContentManager.Templating.Engine.InvokeTemplate(Package package, TemplateInvocation templateInvocation, Template template)
at Tridion.ContentManager.Templating.Compound.CompoundTemplateMediator.Transform(Engine engine, Template templateToTransform, Package package) at Tridion.ContentManager.Templating.Engine.ExecuteTemplate(Template template, Package package) at Tridion.ContentManager.Templating.Engine.InvokeTemplate(Package package, TemplateInvocation templateInvocation, Template template)
at Tridion.ContentManager.Templating.Engine.TransformPackage(Template template, Package package) at Tridion.ContentManager.Templating.Engine.TransformItem(Template template, IdentifiableObject itemToRender) at Tridion.ContentManager.Templating.Debugging.DebuggingEngine.Run()
at Tridion.ContentManager.Templating.Debugging.DebugSession.Run()
Thanks in advance for your help
EDIT:
This is the (simplified) Schema for the Component:
<xsd:schema targetNamespace="uuid:8B3F97F1-78E6-492E-A1F5-2B312F5C1203" elementFormDefault="qualified" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance" xmlns="uuid:8B3F97F1-78E6-492E-A1F5-2B312F5C1203">
<xsd:annotation>
<xsd:appinfo>
<tcm:Labels>
<tcm:Label ElementName="Paragraph" Metadata="false">Paragraph</tcm:Label>
</tcm:Labels>
</xsd:appinfo>
</xsd:annotation>
<xsd:include schemaLocation="tcm:120-13617-8"/>
<xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance"/>
<xsd:element name="Content">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Paragraph" minOccurs="1" maxOccurs="unbounded" type="paragraph">
<xsd:annotation>
<xsd:appinfo>
<tcm:EmbeddedSchema xlink:href="tcm:120-13617-8" xlink:title="ESC_Paragraph"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
And the (simplified) Embedded Schema:
<xsd:schema elementFormDefault="qualified" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance">
<xsd:annotation>
<xsd:appinfo>
<tcm:Labels>
<tcm:Label ElementName="slideshare" Metadata="false">slideshare</tcm:Label>
</tcm:Labels>
</xsd:appinfo>
</xsd:annotation>
<xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance"/>
<xsd:complexType name="paragraph">
<xsd:sequence>
<xsd:element name="slideshare" minOccurs="0" maxOccurs="1" type="tcmi:SimpleLink">
<xsd:annotation>
<xsd:appinfo>
<tcm:linktype>ComponentLink</tcm:linktype>
<tcm:AllowMultimediaLinks>false</tcm:AllowMultimediaLinks>
<tcm:AllowedTargetSchemas>
<tcm:TargetSchema xlink:href="tcm:120-48342-8" xlink:title="SC_Slideshare"/>
</tcm:AllowedTargetSchemas>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Schreenshot of the entire Schema, indicating the field in question: