System.InvalidCastException

May 15, 2010 at 5:44 PM
Edited May 15, 2010 at 5:45 PM

Hi, If i am using block-container, i am getting System.InvalidCastException invalid exception.
I have copied the code hello.fo

<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
<fo:simple-page-master master-name="simple"
page-height="12in"
page-width="8.5in">
<fo:region-body margin-top="3cm"/>
<fo:region-before extent="3cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body"> 
<fo:block>
<fo:block-container absolute-position="absolute" top="35mm" left="00mm" width="78mm" height="60mm" font-size="12pt" border-style="solid" border-color="#DDDDDD">
<fo:block text-align="justify">
<fo:block>This is a block container.</fo:block>
</fo:block>
</fo:block-container>
</fo:block> 
</fo:flow>
</fo:page-sequence>
</fo:root>

and the error is
System.InvalidCastException: Unable to cast object of type 'Fonet.Layout.BlockArea' to type 'Fonet.Layout.AreaContainer'.
at Fonet.Fo.Flow.BlockContainer.Layout(Area area) in C:\Projects\DesignPatterns\FOSample\Core\Fo\Flow\BlockContainer.cs:line 61
at Fonet.Fo.Flow.Block.Layout(Area area) in C:\Projects\DesignPatterns\FOSample\Core\Fo\Flow\Block.cs:line 220
at Fonet.Fo.Flow.Flow.Layout(Area area, Region region) in C:\Projects\DesignPatterns\FOSample\Core\Fo\Flow\Flow.cs:line 123
at Fonet.Fo.Flow.Flow.Layout(Area area) in C:\Projects\DesignPatterns\FOSample\Core\Fo\Flow\Flow.cs:line 82
at Fonet.Fo.Pagination.PageSequence.Format(AreaTree areaTree) in C:\Projects\DesignPatterns\FOSample\Core\Fo\Pagination\PageSequence.cs:line 216
at Fonet.StreamRenderer.Render(PageSequence pageSequence) in C:\Projects\DesignPatterns\FOSample\Core\StreamRenderer.cs:line 107
at Fonet.Fo.FOTreeBuilder.EndElement() in C:\Projects\DesignPatterns\FOSample\Core\Fo\FOTreeBuilder.cs:line 175
at Fonet.Fo.FOTreeBuilder.Parse(XmlReader reader) in C:\Projects\DesignPatterns\FOSample\Core\Fo\FOTreeBuilder.cs:line 219

Please help me how to correct it?
Thanks
Kousikan

Jun 4, 2010 at 10:37 AM

Hi Kousikan,

I had a similar issue with <xsl:block-container> - the fixes I applied to code were...

in Core\Flow\BlockContainer.cs - go to the Layout() method and make the following changes...

  1. Comment out the line:-
      AreaContainer container = (AreaContainer)area;
  2. Replace this bit of code...
      this.areaContainer =
                    new AreaContainer(propMgr.GetFontState(container.getFontInfo()),
                                      container.getXPosition() + left,
                                      container.GetYPosition() - top, width, height,
                                      position);
    with...
      this.areaContainer =
                    new AreaContainer(propMgr.GetFontState(area.getFontInfo()),
                                      left,
                                      top, width, height,
                                      position);
  3. In order to get absolute height to work, replace this bit of code...
      if (position == Position.ABSOLUTE)
    with...
      if (this.properties.GetProperty("absolute-position").GetEnum() == Position.ABSOLUTE)

 Hope this helps

Marrow