Why does IPolygon.Overlap(IPolygon) use reflection to load client assemblies?

07-12-2011 08:20 AM
New Contributor
I have a simple piece of code that checks whether an envelope overlaps a polygon:

        bool IsOverlap(IPolygon p, IEnvelope e)
            IPolygon pe = new PolygonClass();
            (pe as ISegmentCollection).SetRectangle(e);
            return (pe as IRelationalOperator).Overlaps(p);            

It was working for me this morning. But this afternoon, the call to IRelationalOperator.Overlaps causes a weird exception, apparently due to some problem reflecting on assemblies. The message is Could not load file or assembly 'Inova.Core.DataStore.XmlSerializers' or one of its dependencies.

I also see Exception from HRESULT: 0x80040215| COM Errorcode -2147220971 [FDO_E_BINDING]

My app does reference a DLL called Inova.Core.DataStore.dll (though I don't know where it's getting the XmlSerializers bit from). The stack trace looks like this:

   at System.Reflection.RuntimeAssembly.nLoad(...
   at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(...
   at ESRI.ArcGIS.Geometry.PolygonClass.Overlaps(IGeometry other)
   at Firefly.Spatial.Survey.Database.BlockWriter.IsOverlap(IPolygon p, IEnvelope e)

Pity the ArcGIS code is top secret because now I have to ask: what's going on, and what can I do?
0 Kudos
3 Replies
New Contributor
Poking around this morning, I found that the following avoided the error:

        int SplitRaster(IRasterDataset rds, IPolygon extent, ...
            IRasterProps rasterProps = (IRasterProps)rds.CreateDefaultRaster();
            IEnvelope dsExtent = rasterProps.Extent;

            // The following leads to weird error
            // if (!IsOverlap(extent, dsExtent))
            //     return 0;
            // This avoids the error
            IEnvelope testExtent = new EnvelopeClass();
            testExtent.PutCoords(dsExtent.XMin, dsExtent.YMin, dsExtent.XMax, dsExtent.YMax);
            if (!IsOverlap(extent, testExtent))
                return 0;

Unfortunately, the result was incorrect. I then noticed that I'd forgotten to copy over the spatial reference. When I did that (i.e. set testExtent.SpatialReference = dsExtent.SpatialReference), the error came back.

So it seems the error is arising during an on-the-fly coordinate conversion (my polygon is NAD27, my raster is NAD83).
0 Kudos
Regular Contributor III
I'm not familiar with the Inova dll so I don't know what it's for or why it's being called.  However, when performing geometric operations with multiple geometries it's usually a good idea to make sure they are all in the same spatial reference.  I check the FactoryCodes of the spatial references involved and if they don't match then I call IGeometry.Project to project one of the geometries into the spatial reference of the other.
0 Kudos
New Contributor
Hi Neil,

Yes, the Inova dll is one of our own low-level DLLs (no ArcGIS in sight) - I couldn't understand why a call to ArcGIS code would end up trying to access it. I can only put it down to the wonders of COM interop.

In the end, I applied an ICoordinateXform to my raster (since the output needs to be in the coordinate system of my polygon). Having done that, the problem disappeared.
0 Kudos