NHibernate
  1. NHibernate
  2. NH-2312

Patch that makes NHibernate 3.0 work on Mono

    Details

    • Type: Patch Patch
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Duplicate
    • Affects Version/s: 3.0.0.Alpha1, 3.0.0.Alpha2, 3.0.0.Alpha3
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      Hello,

      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:
      (Shortened)
      To be XML serializable, types which inherit from IEnumerable must have an implementation of Add at all levels of their inheritance hierarchy.

      Background:

      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:
      https://nhibernate.jira.com/browse/NH-1865

      There is also a bug report on Mono's bug tracker:
      https://bugzilla.novell.com/show_bug.cgi?id=519442

      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.

        Issue Links

          Activity

          Hide
          Fabio Maulo added a comment -

          Only as comment, IMO the "errornous behavior" is the serialization of properties without a state.
          The serialization is to serialize the state (fields) of an object and not the behavior (methods).

          Show
          Fabio Maulo added a comment - Only as comment, IMO the "errornous behavior" is the serialization of properties without a state. The serialization is to serialize the state (fields) of an object and not the behavior (methods).
          Hide
          Timur Kristóf added a comment -

          Anyways, could you please apply the patch?
          It makes no harm. Many people would be very happy if they could see NHibernate working on Mono.

          Show
          Timur Kristóf added a comment - Anyways, could you please apply the patch? It makes no harm. Many people would be very happy if they could see NHibernate working on Mono.

            People

            • Assignee:
              Unassigned
              Reporter:
              Timur Kristóf
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Who's Looking?