Invalid attempt to call MetaData when reader is closed.

305 views
Skip to first unread message

kyle@rpmware

unread,
May 1, 2008, 11:52:08 AM5/1/08
to Castle Project Users
public partial class ItmBrand
{
private static readonly IWindsorContainer container = new
WindsorContainer(new XmlInterpreter());

//Constructor
protected ItmBrand()
{
CliClient = container.Resolve<CliClient>();
}

public static ItmBrand[] GetBrands()
{

return FindAll();
}
...
}

<!-- Windsor -->
<castle>
<facilities>
<facility id="rails.facility"
type="Castle.MonoRail.WindsorExtension.MonoRailFacility,
Castle.MonoRail.WindsorExtension" />
<facility id="factorysupport"
type="Castle.Facilities.FactorySupport.FactorySupportFacility,
Castle.MicroKernel" />
</facilities>
<components>
<component id="Session.Factory"
type="RPMWare.CoreProduct.Web.UI.SessionFactory,
RPMWare.CoreProduct.Web.UI" lifestyle="transient"/>
<component id="CliClient.default"
type="RPMWare.Core.Model.CliClient, RPMWare.Core.Model"
factoryId="Session.Factory" factoryCreate="GetClientInstance"
lifestyle="transient" />
<component id="CliService.default"
type="RPMWare.Core.Model.CliService, RPMWare.Core.Model"
factoryId="Session.Factory" factoryCreate="GetServiceInstance"
lifestyle="transient" />
</components>
</castle>
<!-- /Windsor-->


When I call GetBrands() from a web app I get the Invalid attempt to
call MetaData when reader is closed. error.
When I comment out the constructor everything works.
In test cases of just the model everything works as is.

Anyone seen this before? Any ideas? Thanks in advance.

kyle@rpmware

unread,
May 1, 2008, 12:09:11 PM5/1/08
to Castle Project Users
Sorry I didn't include this in the original post ... here is the stack
trace:

[InvalidOperationException: Invalid attempt to call MetaData when
reader is closed.]
System.Data.SqlClient.SqlDataReader.get_MetaData() +894237
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +54
NHibernate.Driver.NHybridDataReader.GetOrdinal(String name) +35
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String
name) +73
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[]
names, ISessionImplementor session, Object owner) +54
NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[]
names, ISessionImplementor session, Object owner) +48

NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(IDataReader
rs, Object id, Object obj, ILoadable rootLoadable, String[][]
suffixedPropertyColumns, Boolean allProperties, ISessionImplementor
session) +1046
NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i,
Object obj, String instanceClass, EntityKey key, LockMode lockMode,
ILoadable rootPersister, ISessionImplementor session) +343
NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32
i, ILoadable persister, EntityKey key, LockMode lockMode, EntityKey
optionalObjectKey, Object optionalObject, IList hydratedObjects,
ISessionImplementor session) +295
NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[]
persisters, EntityKey[] keys, Object optionalObject, EntityKey
optionalObjectKey, LockMode[] lockModes, IList hydratedObjects,
ISessionImplementor session) +406
NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet,
ISessionImplementor session, QueryParameters queryParameters,
LockMode[] lockModeArray, EntityKey optionalObjectKey, IList
hydratedObjects, EntityKey[] keys, Boolean returnProxies) +402
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
QueryParameters queryParameters, Boolean returnProxies) +684

NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor
session, QueryParameters queryParameters, Boolean returnProxies) +105
NHibernate.Loader.Loader.DoList(ISessionImplementor session,
QueryParameters queryParameters) +217

[ADOException: could not execute query
[ SELECT this_.Id as Id32_0_, this_.IsActive as IsActive32_0_,
this_.DateAdded as DateAdded32_0_, this_.DateModified as
DateModi4_32_0_, this_.Code as Code32_0_, this_.Name as Name32_0_,
this_.Image as Image32_0_, this_.Description as Descript8_32_0_,
this_.ClientId as ClientId32_0_ FROM dbo.ItmBrands this_ ]
[SQL: SELECT this_.Id as Id32_0_, this_.IsActive as IsActive32_0_,
this_.DateAdded as DateAdded32_0_, this_.DateModified as
DateModi4_32_0_, this_.Code as Code32_0_, this_.Name as Name32_0_,
this_.Image as Image32_0_, this_.Description as Descript8_32_0_,
this_.ClientId as ClientId32_0_ FROM dbo.ItmBrands this_]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session,
QueryParameters queryParameters) +348
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor
session, QueryParameters queryParameters) +46
NHibernate.Loader.Loader.List(ISessionImplementor session,
QueryParameters queryParameters, ISet`1 querySpaces, IType[]
resultTypes) +152
NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor
session) +67
NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList
results) +502
NHibernate.Impl.CriteriaImpl.List(IList results) +65
NHibernate.Impl.CriteriaImpl.List() +55
Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType,
Order[] orders, ICriterion[] criteria) +243

[ActiveRecordException: Could not perform FindAll for ItmBrand]
Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType,
Order[] orders, ICriterion[] criteria) +396
Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType) +44
Castle.ActiveRecord.ActiveRecordBase`1.FindAll() +77
RPMWare.Core.Model.ItmBrand.GetActiveBrandsForCatalog() in D:
\Documents\RPMWare\RPMWare.Development\RPMWare.Core\RPMWare.Core.Model
\Business\ItmBrand.cs:62
RPMWare.CoreProduct.Web.UI.BrandListComponent.Render() in D:
\Documents\RPMWare\RPMWare.Development\RPMWare.CoreProduct
\RPMWare.CoreProduct.Web.UI\Controllers\Components
\BrandListComponent.cs:19

Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives.AbstractComponentDirective.Render(IInternalContextAdapter
context, TextWriter writer, INode node) +2271

NVelocity.Runtime.Parser.Node.ASTDirective.Render(IInternalContextAdapter
context, TextWriter writer) +116

NVelocity.Runtime.Parser.Node.SimpleNode.Render(IInternalContextAdapter
context, TextWriter writer) +91

Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives.AbstractComponentDirective.RenderView(IInternalContextAdapter
context, String viewToRender, Template template, TextWriter writer)
+111

Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives.AbstractComponentDirective.RenderComponentView(IInternalContextAdapter
context, String viewToRender, TextWriter writer,
NVelocityViewContextAdapter contextAdapter) +131

Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives.AbstractComponentDirective.Render(IInternalContextAdapter
context, TextWriter writer, INode node) +2354

NVelocity.Runtime.Parser.Node.ASTDirective.Render(IInternalContextAdapter
context, TextWriter writer) +116

NVelocity.Runtime.Parser.Node.SimpleNode.Render(IInternalContextAdapter
context, TextWriter writer) +91
NVelocity.Template.Merge(IContext context, TextWriter writer) +228

Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine.Process(String
viewName, TextWriter output, IEngineContext context, IController
controller, IControllerContext controllerContext) +508

Castle.MonoRail.Framework.Services.DefaultViewEngineManager.Process(String
templateName, TextWriter output, IEngineContext context, IController
controller, IControllerContext controllerContext) +222
Castle.MonoRail.Framework.Controller.ProcessView() +110
RPMWare.CoreProduct.Web.UI.ControllerBase.ProcessView() in D:
\Documents\RPMWare\RPMWare.Development\RPMWare.CoreProduct
\RPMWare.CoreProduct.Web.UI\Code\ControllerBase.cs:54
Castle.MonoRail.Framework.Controller.RunActionAndRenderView() +1779
Castle.MonoRail.Framework.Controller.Process(IEngineContext
engineContext, IControllerContext context) +55
Castle.MonoRail.Framework.BaseHttpHandler.Process(HttpContext
context) +141

[MonoRailException: Error processing MonoRail request. Action default
on controller home]
Castle.MonoRail.Framework.BaseHttpHandler.Process(HttpContext
context) +429

Castle.MonoRail.Framework.BaseHttpHandler.ProcessRequest(HttpContext
context) +29

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously) +64

josh robb

unread,
May 1, 2008, 10:32:16 PM5/1/08
to castle-pro...@googlegroups.com
On Fri, May 2, 2008 at 1:52 AM, kyle@rpmware <ksw...@gmail.com> wrote:
> When I call GetBrands() from a web app I get the Invalid attempt to
> call MetaData when reader is closed. error.
> When I comment out the constructor everything works.
> In test cases of just the model everything works as is.
>
> Anyone seen this before? Any ideas? Thanks in advance.

Yep - seen it before. IIRC - it was related to accessing AR/NH from
constructors before a SessionScope was opened. (I think?).

It started occurring for me when I upgraded from NH 1 -> 1.2.

I solved it by lazily doing the NH operations.

j.

kyle@rpmware

unread,
May 2, 2008, 12:52:32 AM5/2/08
to Castle Project Users
I thought that too, but this doesn't work either.

using (new SessionScope())
{
ItmBrand[] Brands = ItmBrand.GetBrands();
PropertyBag["brandlist_brands"] = Brands;
RenderView("default");
}

We're you speaking of something else? I'm using the Castle Trunk.

Thanks,

Kyle

josh robb

unread,
May 6, 2008, 2:20:42 AM5/6/08
to castle-pro...@googlegroups.com
On Fri, May 2, 2008 at 2:52 PM, kyle@rpmware <ksw...@gmail.com> wrote:
>
> I thought that too, but this doesn't work either.
>
> using (new SessionScope())
> {
> ItmBrand[] Brands = ItmBrand.GetBrands();
> PropertyBag["brandlist_brands"] = Brands;
> RenderView("default");
> }
>
> We're you speaking of something else? I'm using the Castle Trunk.
>

That wouldn't make any difference.

See this thread on the forum:
http://forum.castleproject.org/viewtopic.php?t=2578

It describes exactly what I was seeing. I didn't bother investigating
it once I'd read that - I just moved my initalization to another
place.

kyle@rpmware

unread,
May 6, 2008, 12:12:12 PM5/6/08
to Castle Project Users
Thanks, I had seen that post and removing the constructor does solve
the problem. However ....

This works (retrieve and iterate) in Tests but not in Web Project ....

private static readonly IWindsorContainer container = new
WindsorContainer(new XmlInterpreter());

public ItmBrand()
{
CliClient = container.Resolve<CliClient>();
}

This works in Tests and Web Project:

public ItmBrand()
{
Name = "Test Name";
}

And of course ... this works in both:

public ItmBrand()
{
}

The only time I get the meta data error is when trying to use Windsor
in the web application project. The Windsor config (above) is
identical in both the Test project and Web App project.

I'm getting ready to just ditch Windsor and add set Client manually on
all objects.

Kyle

josh robb

unread,
May 7, 2008, 11:21:27 PM5/7/08
to castle-pro...@googlegroups.com
On Wed, May 7, 2008 at 2:12 AM, kyle@rpmware <ksw...@gmail.com> wrote:
> The only time I get the meta data error is when trying to use Windsor
> in the web application project. The Windsor config (above) is
> identical in both the Test project and Web App project.
>
> I'm getting ready to just ditch Windsor and add set Client manually on
> all objects.

I'm out of ideas - but as another data point - I wasn't even using
Windsor on the project I had this problem on - it was strictly AR.

j.

Reply all
Reply to author
Forward
0 new messages