I'm trying to implement a custom PropertyAccessor but I'm getting an 'Object reference not set to an instance of an object' exception:
Code:
[NullReferenceException: Object reference not set to an instance of an object.]
NHibernate.Util.ReflectHelper.GetGetter(Type theClass, String propertyName, String propertyAccessorName) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Util\ReflectHelper.cs:102
NHibernate.Util.ReflectHelper.ReflectedPropertyType(Type theClass, String name, String propertyAccess) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Util\ReflectHelper.cs:164
NHibernate.Mapping.SimpleValue.SetTypeByReflection(Type propertyClass, String propertyName, String propertyAccess) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Mapping\SimpleValue.cs:155
NHibernate.Cfg.Binder.BindRootClass(XmlNode node, RootClass model, Mappings mappings) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Binder.cs:351
NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Binder.cs:1536
NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Configuration.cs:228
NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Configuration.cs:542
NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Configuration.cs:425
I've specified the custom accessor in my mapping file by setting the property access to my custom PropertyAccessor (which is derived from the BasicPropertyAccessor) using the fully qualified name of the class like so:
Code:
access="Framework.Core.CustomPropertyAccessor, Framework.Core"
It appears that when ReflectHelper.GetGetter is called the accessor returned from the PropertyAccessorFactory.PropertyAccessors[ propertyAccessorName ] (see below) returns null so when the attempt to get the getter in the following line throws the exception, which is not caught.
Code:
public static IGetter GetGetter( System.Type theClass, string propertyName, string propertyAccessorName )
{
IPropertyAccessor accessor = null;
try
{
// first try the named strategy since that will be the most likely strategy used.
accessor = ( IPropertyAccessor ) PropertyAccessorFactory.PropertyAccessors[ propertyAccessorName ];
return accessor.GetGetter( theClass, propertyName );
}
catch( PropertyNotFoundException )
{
// the basic named strategy did not work so try the rest of them
foreach( DictionaryEntry de in PropertyAccessorFactory.PropertyAccessors )
{
try
{
accessor = ( IPropertyAccessor ) de.Value;
return accessor.GetGetter( theClass, propertyName );
}
catch( PropertyNotFoundException )
{
// ignore this exception because we want to try and move through
// the rest of the accessor strategies.
}
}
throw;
}
}
Is this being caused because I've done something wrong in my mapping file when declaring the custom PropertyAccessor, or is this a bug?
Cheers,
Symon.