'GeoAPI.Geometries.IGeometry' handled by 'NHibernate.Spatial.Type.GeometryType' is not Serializable

709 Views Asked by At

We're using several webapplications using NHibernate to connect to a PostGIS server. Our log files are flooded with this warning:

the custom type 'GeoAPI.Geometries.IGeometry' handled by 'NHibernate.Spatial.Type.GeometryType' is not Serializable

I've searched using Google and see a lot of other people reporting the same problem but I haven't found any solution.

I'm not even sure if it is an issue with NHibernate or with GeoAPI.

Any help is much appreciated.

1

There are 1 best solutions below

3
On BEST ANSWER

I can show you a chain of events which lead to this warning.

  1. PostGisDialect.cs - this is dialect used with PostGIS. Note that:

    public IGeometryUserType CreateGeometryUserType()
    {
        return new PostGisGeometryType();
    }
    
  2. PostGisGeometryType - note that it implements GeometryTypeBase.

  3. GeometryTypeBase. Note that:

    public System.Type ReturnedType
    {
        get { return typeof(IGeometry); }
    }
    
  4. GeometryType.cs - now this one is used to handle your geometry column mappings. Note that:

    this.geometryUserType = SpatialDialect.LastInstantiated.CreateGeometryUserType();
    ...
    public System.Type ReturnedType
    {
        get { return this.geometryUserType.ReturnedType; }
    }
    
  5. Last piece: CustomType:

    if (!userType.ReturnedType.IsSerializable)
    {
        LoggerProvider.LoggerFor(typeof(CustomType)).WarnFormat("the custom type '{0}' handled by '{1}' is not Serializable: ", userType.ReturnedType, userTypeClass);
    }
    

So GeometryType.ReturnValue should be serializable to avoid this warning. GeometryType uses PostGisDialect, which in turn uses PostGisGeometryType, which inherits from GeometryTypeBase, which always returns IGeometry as it's ReturnedType. Of course interface cannot be serializable, hence this warning (and it should produce the same warning for any geometry type that inherit from GeometryTypeBase actually, like Oracle or Sql Server). Actual types that implement IGeometry are in fact serializable.

What is the summary? I think this check just returns false positive in this case. Maybe it should check if ReturnType is interface and in such case do not produce warning. Using interface here is completely legitimate.

There is actually open issue about this: here, which is 2 years old, but they did not dig deep enough to realize what the actual issue is it seems. I'll post them a link to this post, maybe they will fix it.