JoinData: Can't create output feature class. the workspaces is not connected.

Discussion created by Kaspatoo on Aug 8, 2011
Latest reply on Aug 11, 2011 by Kaspatoo

I have a FeatureClass with polylines and one point. I know the point must (almost) lie on one of the polylines.

The Point is stored as shape in a featureClass created by in a scratchworkspace.

To identify which polyline it is I make use of the ISpatialJoin Interface.
The Polyline FeatureClass is set as sourceTable, while the point FeatureClass is set as the JoinTable (both are casted to ITable before)

when now executing
IFeatureClass nearestContour = join.JoinNearest(name, -1);

I will get the Error as in subject:
Can't create output feature class. the workspaces is not connected.

Which workspace is meant? The scratch? Theres no order to close its connection. Is there may another way to create a feature class for a given IPoint, without workspaces?

the whole code:
private double getheightAtPoint(IFeatureClass contourClass, IPoint point)
                IScratchWorkspaceFactory2 scratchWorkspaceFactory = (IScratchWorkspaceFactory2)new FileGDBScratchWorkspaceFactory();
                IWorkspace scratchWorkspace = (IWorkspace)scratchWorkspaceFactory.CreateNewScratchWorkspace();
                IFeatureClass pointClass = Utilities.Instance.CreateFeatureClassInWorkspace("tmpPoint", (IFeatureWorkspace)scratchWorkspace);

                IFeature pointFeature = pointClass.CreateFeature();
                pointFeature.Shape = point;

                IFeatureCursor contourCursor = contourClass.Search(null, false);
                IFeature contourFeature = contourCursor.NextFeature();
                IPolyline pPolyline = contourFeature.Shape as IPolyline;
                double height = 0;
                ISpatialJoin join = new SpatialJoinClass();

                join.SourceTable = contourClass as ITable;
                join.JoinTable = pointClass as ITable;

                IName name = new FeatureClassName();
                name.NameString = "nearestContour";

                IFeatureClass nearestContour = join.JoinNearest(name, -1);
                int index = nearestContour.Fields.FindField("Contour");

                if (index != -1)
                    height = (Double)(nearestContour as IRow).get_Value(index);
                    throw new NullReferenceException("Es konnte kein Contour-Feld gefunden werden!");
                return height;
            catch (Exception e)
                throw e;

Thanks for any help and ideas.