We're trying to upgrade from NH 2.0.1 to NH 2.1.2. When we access an uninitialized collection mapped as a bag, we get a NullReferenceException from GenericPersistentBag.GetEnumerator().
Looking at the code, if the constructor just taking a session is called, it never initializes the private field gbag. It looks like almost all the other classes in NHibernate\Collection and NHibernate\Collection\Generic have this kind of problem.
I worked around it by modifying the constructor from
Code:
public PersistentGenericBag(ISessionImplementor session) : base(session) {}
to
Code:
public PersistentGenericBag(ISessionImplementor session) : this(session, new List<T>()) {}
GenericPersistentBag.cs (and probably the other collection classes) have changed since NH 2.0.1, but the older code still has similar problems. Apparently something changed in NH so that these constructors are now getting called when they weren't before?
Hasn't anyone else seen this problem? My confidence in NH is dropping after seeing these glaring bugs in the code ...