1
Vote

Tokens using MediaLibraryPicker and output rewrite throw an error

description

In Orchard 1.7.1 and 1.7.2 I was using Tokens to rewrite output in a query. The selected field to be rewritten was a Media Library Picker field. I observed the following exception :

2014-01-21 00:27:29,405 [7] Orchard.Exceptions.DefaultExceptionPolicy - An unexpected exception was caught
NHibernate.Exceptions.GenericADOException: could not load an entity: [Orchard.ContentManagement.Records.ContentItemRecord#0][SQL: SELECT contentite0_.Id as Id427_0_, contentite0_.Data as Data427_0_, contentite0_.ContentType_id as ContentT3_427_0_ FROM Orchard_Framework_ContentItemRecord contentite0_ WHERE contentite0_.Id=?] ---> System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is closed.
at System.Data.SqlClient.SqlConnection.GetOpenConnection(String method)
at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\AdoNet\AbstractBatcher.cs:line 247
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Loader\Loader.cs:line 1226
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Loader\Loader.cs:line 421
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Loader\Loader.cs:line 251
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Loader\Loader.cs:line 1279
--- End of inner exception stack trace ---
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Loader\Loader.cs:line 1288
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Loader\Entity\AbstractEntityLoader.cs:line 44
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Loader\Entity\AbstractEntityLoader.cs:line 39
at NHibernate.Event.Default.DefaultLoadEventListener.LoadFromDatasource(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultLoadEventListener.cs:line 351
at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultLoadEventListener.cs:line 110
at Orchard.Data.Providers.AbstractDataServicesProvider.OrchardLoadEventListener.OnLoad(LoadEvent event, LoadType loadType) in c:\web\TritonDigital\src\Orchard\Data\Providers\AbstractDataServicesProvider.cs:line 130
at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 2527
at NHibernate.Impl.SessionImpl.Get(String entityName, Object id) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1367
at NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1303
at NHibernate.Impl.SessionImpl.Get[T](Object id) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1287
at Orchard.Data.Repository1.Get(Int32 id) in c:\web\TritonDigital\src\Orchard\Data\Repository.cs:line 87
at Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options, QueryHints hints) in c:\web\TritonDigital\src\Orchard\ContentManagement\DefaultContentManager.cs:line 199
at Orchard.MediaLibrary.Tokens.FieldTokens.<Evaluate>b__a(MediaLibraryPickerField field)
at Orchard.Tokens.Implementation.TokenManager.EvaluateContextImpl.EvaluateForImpl
1.Chain(String token, String chainTarget, Func2 chainValue)
at Orchard.MediaLibrary.Tokens.FieldTokens.Evaluate(EvaluateContext context)
at Orchard.Events.DelegateHelper.<>c__DisplayClass2b
2.<BuildAction>b__2a(Object target, Object[] p) in c:\web\TritonDigital\src\Orchard\Events\DelegateHelper.cs:line 116
at Orchard.Events.DefaultOrchardEventBus.TryInvokeMethod(IEventHandler eventHandler, Type interfaceType, String messageName, String interfaceName, String methodName, IDictionary2 arguments, IEnumerable& returnValue) in c:\web\TritonDigital\src\Orchard\Events\DefaultOrchardEventBus.cs:line 81
at Orchard.Events.DefaultOrchardEventBus.TryNotifyHandler(IEventHandler eventHandler, String messageName, String interfaceName, String methodName, IDictionary
2 eventData, IEnumerable& returnValue) in c:\web\TritonDigital\src\Orchard\Events\DefaultOrchardEventBus.cs:line 53
2014-01-21 00:27:29,421 [7] NHibernate.AdoNet.AbstractBatcher - Could not execute query: SELECT contentite0_.Id as Id427_0_, contentite0_.Data as Data427_0_, contentite0_.ContentType_id as ContentT3_427_0_ FROM Orchard_Framework_ContentItemRecord contentite0_ WHERE contentite0_contentite0_.Id=@p0 System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is closed.
at System.Data.SqlClient.SqlConnection.GetOpenConnection(String method)
at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\AdoNet\AbstractBatcher.cs:line 223
2014-01-21 00:27:29,421 [7] NHibernate.Util.ADOExceptionReporter - ExecuteReader requires an open and available Connection. The connection's current state is closed.
2014-01-21 00:27:29,421 [7] NHibernate.Util.ADOExceptionReporter - ExecuteReader requires an open and available Connection. The connection's current state is closed.

I had a Content Type called "Client Logo". It had a field on it of type Media Library Picker. I then had a Query pulling in all ContentTypes="ClientLogo" bound to a projection. Inside my query setup I added a new layout with the following settings :

Display Mode : Properties
Properties : My MediaLibraryPicker field

Then on the property details I chose to "Rewrite output" and used this string with tokens in it :
<img class="client" src="{Content.Fields.Client.ClientLogo.Url.Absolute}" alt="{Content.Fields.Client.ClientLogo.AlternateText}" /> This was throwing an error randomly and was not easily reproducible. Possibly a null value for the MediaPicker field may be the reason.

comments