codesharp / infrastructure

code# opensource infrastructure/framework
5 stars 2 forks source link

FluentNHibernate "Object reference not set to an instance of an object" #18

Closed wsky closed 12 years ago

wsky commented 12 years ago

fluentnh在mono下,部分情况映射时发生如下异常

Errors and Failures: [exec] 1) SetUp Error : Cooper.Model.Test.AccountConnectionTest [exec] SetUp : System.NullReferenceException : Object reference not set to an instance of an object [exec] at FluentNHibernate.Visitors.DefaultMappingModelVisitor.Visit (FluentNHibernate.MappingModel.ColumnMapping columnMapping) [0x00000] in :0 [exec] at FluentNHibernate.MappingModel.PropertyMapping.AcceptVisitor (IMappingModelVisitor visitor) [0x00000] in :0 [exec] at FluentNHibernate.Visitors.DefaultMappingModelVisitor.Visit (FluentNHibernate.MappingModel.PropertyMapping propertyMapping) [0x00000] in :0 [exec] at FluentNHibernate.MappingModel.MappedMembers.AcceptVisitor (IMappingModelVisitor visitor) [0x00000] in :0 [exec] at FluentNHibernate.MappingModel.ClassBased.ClassMappingBase.AcceptVisitor (IMappingModelVisitor visitor) [0x00000] in :0 [exec] at FluentNHibernate.MappingModel.ClassBased.SubclassMapping.AcceptVisitor (IMappingModelVisitor visitor) [0x00000] in :0 [exec] at FluentNHibernate.Visitors.DefaultMappingModelVisitor.Visit (FluentNHibernate.MappingModel.ClassBased.SubclassMapping subclassMapping) [0x00000] in :0 [exec] at FluentNHibernate.MappingModel.ClassBased.ClassMappingBase.AcceptVisitor (IMappingModelVisitor visitor) [0x00000] in :0 [exec] at FluentNHibernate.MappingModel.ClassBased.ClassMapping.AcceptVisitor (IMappingModelVisitor visitor) [0x00000] in :0 [exec] at FluentNHibernate.Visitors.DefaultMappingModelVisitor.Visit (FluentNHibernate.MappingModel.ClassBased.ClassMapping classMapping) [0x00000] in :0 [exec] at FluentNHibernate.MappingModel.HibernateMapping.AcceptVisitor (IMappingModelVisitor visitor) [0x00000] in :0 [exec] at FluentNHibernate.Visitors.DefaultMappingModelVisitor.b0 (FluentNHibernate.MappingModel.HibernateMapping x) [0x00000] in :0 [exec] at FluentNHibernate.Utils.CollectionExtensions.Each[HibernateMapping](IEnumerable1 enumerable, System.Action1 each) [0x00000] in :0 [exec] at FluentNHibernate.Visitors.DefaultMappingModelVisitor.Visit (IEnumerable1 mappings) [0x00000] in <filename unknown>:0 [exec] at FluentNHibernate.PersistenceModel.ApplyVisitors (IEnumerable1 mappings) [0x00000] in :0 [exec] at FluentNHibernate.PersistenceModel.BuildMappings () [0x00000] in :0 [exec] at FluentNHibernate.PersistenceModel.EnsureMappingsBuilt () [0x00000] in :0 [exec] at FluentNHibernate.PersistenceModel.Configure (NHibernate.Cfg.Configuration cfg) [0x00000] in :0 [exec] at FluentNHibernate.ConfigurationHelper.AddMappingsFromAssembly (NHibernate.Cfg.Configuration configuration, System.Reflection.Assembly assembly) [0x00000] in :0 [exec] at CodeSharp.Core.Castles.FluentNHibernateConfigurationBuilder+<>cDisplayClass2.b__0 (IConfiguration o) [0x00000] in :0 [exec] at System.Collections.Generic.List1[Castle.Core.Configuration.IConfiguration].ForEach (System.Action1 action) [0x00000] in :0 [exec] at CodeSharp.Core.Castles.FluentNHibernateConfigurationBuilder.GetConfiguration (IConfiguration facilityConfiguration) [0x00000] in :0 [exec] at Castle.Facilities.NHibernateIntegration.NHibernateFacility.ConfigureFactories (Castle.Facilities.NHibernateIntegration.NHibernateFactoryConfiguration config, ISessionFactoryResolver sessionFactoryResolver, Boolean firstFactory) [0x00000] in :0 [exec] at Castle.Facilities.NHibernateIntegration.NHibernateFacility.ConfigureFacility () [0x00000] in :0 [exec] at Castle.Facilities.NHibernateIntegration.NHibernateFacility.Init () [0x00000] in :0 [exec] at Castle.MicroKernel.Facilities.AbstractFacility.Castle.MicroKernel.IFacility.Init (IKernel kernel, IConfiguration facilityConfig) [0x00000] in :0 [exec] at Castle.MicroKernel.DefaultKernel.AddFacility (IFacility facility) [0x00000] in :0 [exec] at Castle.Windsor.WindsorContainer.AddFacility (IFacility facility) [0x00000] in :0 [exec] at Castle.Windsor.Installer.DefaultComponentInstaller.SetUpFacilities (Castle.Core.Configuration.IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) [0x00000] in :0 [exec] at Castle.Windsor.Installer.DefaultComponentInstaller.SetUp (IWindsorContainer container, IConfigurationStore store) [0x00000] in :0 [exec] at Castle.Windsor.WindsorContainer.Install (Castle.MicroKernel.Registration.IWindsorInstaller[] installers, Castle.Windsor.Installer.DefaultComponentInstaller scope) [0x00000] in :0 [exec] at Castle.Windsor.WindsorContainer.Install (Castle.MicroKernel.Registration.IWindsorInstaller[] installers) [0x00000] in :0 [exec] at (wrapper remoting-invoke-with-check) Castle.Windsor.WindsorContainer:Install (Castle.MicroKernel.Registration.IWindsorInstaller[]) [exec] at CodeSharp.Core.Castles.ConfigurationExtensions.Castle (CodeSharp.Core.Configuration configuration, System.Action`1 func) [0x00000] in :0 [exec] at Cooper.Model.Test.TestBase.TestFixtureSetUp () [0x00000] in :0

wsky commented 12 years ago

https://github.com/jagregory/fluent-nhibernate/blob/master/src/FluentNHibernate/Visitors/DefaultMappingModelVisitor.cs#L127 error occur here

public override void Visit(ColumnMapping columnMapping)
        {
            columnMapping.AcceptVisitor(this);
        }

columnMapping is null

and why?

wsky commented 12 years ago

https://github.com/jagregory/fluent-nhibernate/blob/master/src/FluentNHibernate/MappingModel/Collections/LayeredColumns.cs#L20

i compile it under mono runtime, and debug into it, i found:

var maxLayer = layeredValues.Keys.Max();
                var values = ((HashSet<ColumnMapping>)layeredValues[maxLayer]);

                foreach (var value in values)
                {
                    yield return value;
                }

eg: values will have null element:

((HashSet<ColumnMapping>)layeredValues[maxLayer])

and try below got none exception..

ublic void AddColumn(int layer, ColumnMapping mapping)
        {
            if(mapping==null)
                throw new Exception();

look like confused..

is it a bug of mono?

HashSrt on mono not work well

wsky commented 12 years ago

solution is use dictionary or add “if”

https://github.com/CV1/fluent-nhibernate/commit/8e13db841b630a538e31b21dcf972bd24b6c529d https://bugzilla.xamarin.com/show_bug.cgi?id=4915

wsky commented 12 years ago

someone had find it https://github.com/jagregory/fluent-nhibernate/pull/156

wsky commented 12 years ago

https://github.com/wsky/fluent-nhibernate/commit/ba36b028e0154514c2744fbd9787d20d522cffe6