Intersect, Union are failing on 10.1

Discussion created by gkar68 on Feb 27, 2013
Latest reply on Feb 28, 2013 by whe-esristaff
I am migrating .NET code that was running against 9.3, to make it work for 10.1.

There is part of the code that is failing when migrate to 10.1 and was working on 9.3

The code was doing intersect twice.
The code is like this

The intersection method is wrapped into this method

public IGeometry GetOverlappedGeometry(IGeometry sourceGeometry, IGeometry targetGeometry)
            IGeometry overlappedGeometry = null;

            if (!IsNullOrEmptyGeometry(sourceGeometry) && !IsNullOrEmptyGeometry(targetGeometry) && IsGeometryIntersect(sourceGeometry, targetGeometry))
                IGeometry localSourceGeometry;
                IGeometry localTargetGeometry;

                if (sourceGeometry.GeometryType > targetGeometry.GeometryType)
                    localSourceGeometry = targetGeometry;
                    localTargetGeometry = sourceGeometry;
                    localSourceGeometry = sourceGeometry;
                    localTargetGeometry = targetGeometry;

                ITopologicalOperator targetOperator = localTargetGeometry as ITopologicalOperator;

                if (targetOperator != null)

                    IGeometry intersectGeometry = targetOperator.Intersect(localSourceGeometry, localSourceGeometry.Dimension);

                    if (!IsNullOrEmptyGeometry(intersectGeometry))
                        overlappedGeometry = intersectGeometry;

            return overlappedGeometry;

So the code is calling this method twice

IGeometry overlapped1 = GetOverlappedGeometry(geom1, geom2);
-- where geom1 is PolylineClass, and geom2 is PolygonClass;

IGeometry overlappe2 = GetOverlappedGeometry(geom2, overlapped1);

-- where geom2 is PolylineClass

The code is failing on the second statement,
and more specifically when we are calling the intersect method
targetOperator.Intersect(localSourceGeometry, localSourceGeometry.Dimension);

and giving this error
Error HRESULT E_FAIL has been returned from a call to a COM component.
System.Runtime.InteropServices.ExternalException {System.Runtime.InteropServices.COMException}

HResult = -2147467259