NHibernate trying to map a Record in bad order ??

Topics: Core, Customizing Orchard, Troubleshooting
Aug 6, 2013 at 2:17 PM
Edited Aug 6, 2013 at 2:20 PM
I have 2 model records in 2 different modules:

record A in module A
record B in module B

module B has a dependency on module A in its module.txt declaration (and I checked it is well readen)

and record B has a foreign key on record A.

mapping is failing because NHibernates tries to map B before A and discovers that A is not mapped when trying to interpret the Foreign key.

then I got this (and strangely Orchard after states thats init is Ok....but the site fails to load)

the bad thing is it has been working before ????

``` 2013-08-06 13:52:26,213 [7] NHibernate.Cfg.Configuration - processing foreign key constraints
2013-08-06 13:52:26,220 [7] NHibernate.Cfg.Configuration - An association from the table Datwendo_Connectors_ConnectorPartRecord refers to an unmapped class: Datwendo.Commerce.Models.CustomerPartRecord
NHibernate.MappingException: An association from the table Datwendo_Connectors_ConnectorPartRecord refers to an unmapped class: Datwendo.Commerce.Models.CustomerPartRecord
2013-08-06 13:53:04,820 [7] Orchard.Environment.DefaultOrchardHost - A tenant could not be started: Default
Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Orchard.Environment.Configuration.ShellSettings, Orchard.Data.ISessionFactoryHolder)' on type 'SqlCeCommandInterpreter'. ---> An association from the table Datwendo_Connectors_ConnectorPartRecord refers to an unmapped class: Datwendo.Commerce.Models.CustomerPartRecord (See inner exception for details.) ---> NHibernate.MappingException: An association from the table Datwendo_Connectors_ConnectorPartRecord refers to an unmapped class: Datwendo.Commerce.Models.CustomerPartRecord
à NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
à NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done)
à NHibernate.Cfg.Configuration.SecondPassCompile()
à NHibernate.Cfg.Configuration.GetObjectData(SerializationInfo info, StreamingContext context)
à System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
à System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
à System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
à System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
à System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
à Orchard.Data.SessionConfigurationCache.StoreConfiguration(ConfigurationCache cache) dans e:\Datwendo\Datwendo\src\Orchard\Data\SessionConfigurationCache.cs:ligne 78
à Orchard.Data.SessionConfigurationCache.GetConfiguration(Func`1 builder) dans e:\Datwendo\Datwendo\src\Orchard\Data\SessionConfigurationCache.cs:ligne 59
à Orchard.Data.SessionFactoryHolder.BuildConfiguration() dans e:\Datwendo\Datwendo\src\Orchard\Data\SessionFactoryHolder.cs:ligne 100
à Orchard.Data.SessionFactoryHolder.GetConfiguration() dans e:\Datwendo\Datwendo\src\Orchard\Data\SessionFactoryHolder.cs:ligne 78
à Orchard.Data.Migration.Interpreters.SqlCeCommandInterpreter..ctor(ShellSettings shellSettings, ISessionFactoryHolder sessionFactoryHolder) dans e:\Datwendo\Datwendo\src\Orchard\Data\Migration\Interpreters\SqlCeCommandInterpreter.cs:ligne 19
à lambda_method(Closure , Object[] )
à Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() dans c:\Projects\OSS\autofac\Core\Source\Autofac\Core\Activators\Reflection\ConstructorParameterBinding.cs:ligne 128
--- Fin de la trace de la pile d'exception interne ---
à Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() dans c:\Projects\OSS\autofac\Core\Source\Autofac\Core\Activators\Reflection\ConstructorParameterBinding.cs:ligne 137
.
.
.
2013-08-06 13:53:05,417 [7] Orchard.Environment.DefaultOrchardHost - Done creating shells
2013-08-06 13:53:05,427 [7] Orchard.Environment.DefaultOrchardHost - Initialized


...
Aug 6, 2013 at 6:45 PM
I discovered strange things in files Settings_ShellFeatureStateRecord & Settings_ShellFeatureRecord: missing feature in the last one and duplicated in the first.
Restarted on a backup and it seems to run now.

I am very surprised that we could add duplicated records in Settings_ShellFeatureStateRecord, shouldn't this be prevented by a unique key on Name column ?
This has certainly be created by a bad formated module.txt ..... very touchy this simple file.

Last point, Orchard was trying to map a module enabled with a dependency on another which was not enabled.

All this in the context of migrating an instance using MediaPickerFields, this is not an easy operation....