Hi Everyone,For some reasons the following code is failing to run the dissolve tool on a feature class that I store in a in-memory workspace. I have checked that the inFClass is valid by querying the number of features inside it, and whether it contains the dissolve field. They appear okay. Everything else seems pretty standard.So what might be incorrect with the code? Thanks,Sanj.private IFeatureClass DissolveAdvancedToMemory(IFeatureWorkspace inMemWS, string InputName, string DissolveField, string OutputName)
{
try
{
Dissolve DissolveDS = new Dissolve();
ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Result;
IFeatureClass inFClass = inMemWS.OpenFeatureClass(InputName);
DissolveDS.in_features = inFClass;
DissolveDS.dissolve_field = DissolveField;
DissolveDS.multi_part = "MULTI_PART";
DissolveDS.unsplit_lines = "DISSOLVE_LINES";
DissolveDS.out_feature_class = OutputName ; // output name is a simple string like "Dissolve_Run"
Result = RunTool(DissolveDS, null);
if (Result == null)
{
Debug.WriteLine("Could not dissolve dataset");
return null;
}
return ReturnFeatureClassfromResult(Result);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString() + " Dissolve error");
return null;
}
}
private static ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult RunTool(ESRI.ArcGIS.Geoprocessor.IGPProcess Process,
ESRI.ArcGIS.esriSystem.ITrackCancel2 TC)
{
ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
GP.AddOutputsToMap = false;
ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Result = new GeoProcessorResult();
try
{
Result = GP.Execute(Process, null) as GeoProcessorResult; // code crashes here
if (Result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
Debug.WriteLine("Geoprocessing Error");
GP.ClearMessages();
return Result;
}
catch (Exception ex)
{
if (Result.MessageCount > 0)
{
for (int count = 0; count < Result.MessageCount; count++)
{
Debug.WriteLine(Result.GetMessage(count));
}
Debug.WriteLine("Geoprocessing Failed");
}
GP.AddOutputsToMap = true;
return null;
}
}
private static ESRI.ArcGIS.Geodatabase.IFeatureClass ReturnFeatureClassfromResult(ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult result)
{
ESRI.ArcGIS.Geodatabase.IGPValue GPVal;
string InMemFC;
ESRI.ArcGIS.Geoprocessing.IGPUtilities3 GPUtil =
new ESRI.ArcGIS.Geoprocessing.GPUtilities() as ESRI.ArcGIS.Geoprocessing.IGPUtilities3;
ESRI.ArcGIS.Geodatabase.IFeatureClass pOutputFC;
try
{
GPVal = result.GetOutput(0);
InMemFC = GPVal.GetAsText();
pOutputFC = GPUtil.OpenFeatureClassFromString(InMemFC);
return pOutputFC;
}
catch (Exception ex)
{
Debug.WriteLine("Return FeatureClass error " + ex.ToString());
return null;
}
}