NHibernate Spatial Mapping returns Antrl error
I am using NHibernate 3.3. I have a case where I want to insert a calculated column that is not referenced.
My domain entity can be boiled down to the form
public class Location
{
public virtual IPoint GeoLocation {get;set;}
}
public class MappingOverride : IAutoMappingOverride<Location>
{
public void Override(AutoMapping<Location> mapping)
{
mapping
.Map(e => e.GeoLocation)
.Column("GeoLocation")
.CustomSqlType("geography")
.CustomType<MsSql2008GeographyType>;
}
}
The column of the table is of the type "Geography"
However, it mistakenly looks like
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at GeoAPI.GeometryServiceProvider.GetLoadableTypes(Assembly assembly)
at GeoAPI.GeometryServiceProvider.ReflectInstance()
at GeoAPI.GeometryServiceProvider.get_Instance()
at NetTopologySuite.Geometries.Geometry.set_SRID(Int32 value)
It says he needs it Antrl.Runtime
, but a very old version. All Antrl.Runtime
nuget packages have a different build ID.
Could not load file or assembly 'antlr.runtime, Version = 2.7.6.2, Culture = neutral, PublicKeyToken = 1790ba318ebc5d56' or one of its dependencies. The system cannot find the file specified.
I was working on a separate project where I used a map by code convention and it works without reference to Antrl.Runtime
.
Need help to point yourself in the right direction ...
source to share
As a standalone example project, I tried something that worked, WHICH DOW NOT WORK in the ASP.NET MVC project itself.
Class definition
public class Location : IEntity
{
public virtual int Id { get; protected set; }
public virtual string LocationName { get; set; }
public virtual IPoint GeoLocation { get; set; }
}
Mapping
public class LocationMapping : IAutoMappingOverride<Location>
{
public void Override(AutoMapping<Location> mapping)
{
mapping.Map(x => x.LocationName).Column("Name");
mapping.Map(x => x.GeoLocation).Column("GeoLocation")
.CustomType<MsSql2008GeographyType>();
}
}
Test
public class WhenSavingGeoLocation : BasePersistanceTest
{
[Test]
public void Save()
{
this.Session
.SaveOrUpdate(new Location {
LocationName = "Category 01",
GeoLocation = new Point(-72.12, 32.2323234) { SRID = 4326 }
});
}
}
NHibernate.Spatial
uses NetTopologicalSuite
which itself GeoAPI
derives from the GeoAPI Library defines the interface GeoAPI.Geometries
, and when loaded / searched , the correct implementation in the current project failed with an Antlr error in the MVC project.
However, he was able to get the implementation NetTopologySuite.NtsGeometryServices
in a separate sample project. The actual code in GeoAPI looking for an implementation is like
private static IGeometryServices ReflectInstance()
{
#if !PCL
var a = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in a)
{
// Take a look at issue 114: http://code.google.com/p/nettopologysuite/issues/detail?id=114
if (assembly is System.Reflection.Emit.AssemblyBuilder) continue;
if (assembly.GetType().FullName == "System.Reflection.Emit.InternalAssemblyBuilder") continue;
if (assembly.GlobalAssemblyCache && assembly.CodeBase == Assembly.GetExecutingAssembly().CodeBase) continue;
foreach (var t in GetLoadableTypes(assembly))
{
if (t.IsInterface) continue;
if (t.IsAbstract) continue;
if (t.IsNotPublic) continue;
if (!typeof(IGeometryServices).IsAssignableFrom(t)) continue;
var constuctors = t.GetConstructors();
foreach (var constructorInfo in constuctors)
{
if (constructorInfo.IsPublic && constructorInfo.GetParameters().Length == 0)
return (IGeometryServices)Activator.CreateInstance(t);
}
}
}
#endif
throw new InvalidOperationException("Cannot use GeometryServiceProvider without an assigned IGeometryServices class");
}
}
This is called when the SRID is set in the geometry. I am assuming there is an assembly reference in my MVC project that makes this look Antlr. There have been suggestions to add a redirect to a new Antlr build. I tried this too, but the error was still recurring.
source to share