Affects Version/s: 3.0.0.Alpha1, 3.0.0.Alpha2, 3.0.0.Alpha3
Fix Version/s: None
I'd like to use NHibernate 3.0 in an ASP.NET project that runs on Mono.
Unfortunately, it doesn't work out of the box, but fortunately a fix was very easy to create.
The error message was this:
To be XML serializable, types which inherit from IEnumerable must have an implementation of Add at all levels of their inheritance hierarchy.
I see that NHibernate uses an XmlSerializer to deserialize the hbm mappings to the classes prefixed with 'Hbm' in NHibernate.Cfg.MappingSchema namespace. There are a couple of properies in this classes that should be excluded from (de)serialization. This means most of the properties of type IEnumerable<T> in many of these classes. Judging from their source code, these properties were never meant to be serialized anyways.
As it turns out, Microsoft.NET silently ignores these properties (this is a completely undocumented and presumably errornous behaviour), but Mono's XmlSerializer throws an exception when it encounters such a property.
The fix is to apply the [XmlIgnore] attribute to each of them.
There was already a similar probem which has now been fixed in NHibernate:
There is also a bug report on Mono's bug tracker:
I'd like to contribute a working patch for the NHibernate trunk that gets rid of the exception on Mono. It doesn't affect functionality on Microsoft.NET at all. (Because the properies in question have never ever needed to (de)serialize.)
It would be a great advantage for NHibernate if it worked on Mono. After applying this patch, it does work for me.
All you need to do is to apply the patch to the \trunk\src\NHibernate\Cfg\MappingSchema folder. (For example, using TortoiseSVN.)
If there are any problems with this patch, please let me know and I will fix it.