我们使用NHibernate连接到PostGIS服务器的几个Web应用程序。 我们的日志文件充斥着这个警告:
the custom type 'GeoAPI.Geometries.IGeometry' handled by 'NHibernate.Spatial.Type.GeometryType' is not Serializable
我使用Google搜索并看到很多其他人报告了同样的问题,但我还没有找到任何解决方案。
我甚至不确定这是NHibernate或GeoAPI的问题。
非常感谢任何帮助。
答案 0 :(得分:2)
I can show you a chain of events which lead to this warning.
PostGisDialect.cs - this is dialect used with PostGIS. Note that:
public IGeometryUserType CreateGeometryUserType()
{
return new PostGisGeometryType();
}
PostGisGeometryType - note that it implements GeometryTypeBase.
GeometryTypeBase. Note that:
public System.Type ReturnedType
{
get { return typeof(IGeometry); }
}
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; }
}
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.