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:simple-page-master master-name="simple"
  <fo:region-body margin-top="3cm"/>
  <fo:region-before extent="3cm"/>
  <fo:region-after extent="1.5cm"/>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body">      
    <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>
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 let me know how to correct it?


claytonrumley wrote Jun 5, 2012 at 6:11 PM

Ran into this problem too...it's a few years old now, but I fixed it by going to line 61 in BlockContainer.cs and altering it from:

AreaContainer container = (AreaContainer) area;


AreaContainer container;

if (area is BlockArea)
container = ((BlockArea)area).getNearestAncestorAreaContainer();
container = (AreaContainer)area;

I still haven't investigated it to see if the layout works the way it's supposed to, but it stopped the exception.

I leave this fix to those who maintain this project to implement in the next release.

Clayton Rumley

wrote Jun 5, 2012 at 6:11 PM

wrote Feb 21, 2013 at 11:01 PM

wrote Jan 7, 2014 at 12:36 PM