When called through the SDK, the Contour tool is failing after renaming a raster, but ONLY if a layer in the map uses the raster as its data source. If I run the GP tools (Rename_management & Contour_sa) directly in Pro, everything works fine, but running the code below makes the Contour tool fail with message "ERROR 010213: Error in reading raster %1." If the raster isn't referenced by a layer, everything works fine as well. The processes are run by separate tools within the Add-in, but I combined the code for quick repro. Any thoughts on why it would fail through the SDK but not through the UI?
It's a file geodatabase raster, and I'm using Pro 2.9.2.
internal static async Task RenameRasterAndGenerateContours()
{
var oldRasterPath = @"directPathToGDB.gdb\test";
var newRasterPath = @"directPathToGDB.gdb\test1";
await QueuedTask.Run(async () =>
{
var progressor = new CancelableProgressorSource().Progressor;
var parameters = new Dictionary<string, object>
{
{ "in_data", oldRasterPath },
{ "out_data", newRasterPath },
{ "data_type", "RasterDataset" }
};
var values = Geoprocessing.MakeValueArray(parameters.Values.ToArray());
var results = await Geoprocessing.ExecuteToolAsync("Rename_management", values, null, progressor, GPExecuteToolFlags.None).ConfigureAwait(true);
if (results.ErrorCode != 0)
{
var messages = new StringBuilder("The Rename geoprocessing tool errored with the following messages:");
messages.AppendLine();
foreach (var message in results.ErrorMessages)
messages.AppendLine($" - {message.Text}");
throw new InvalidOperationException(messages.ToString());
}
}).ConfigureAwait(true);
var contourInterval = "42";
var contourPath = $"{newRasterPath}_contour_{contourInterval}";
await QueuedTask.Run(async () =>
{
var progressor = new CancelableProgressorSource().Progressor;
var parameters = new Dictionary<string, object>
{
{ "in_raster", newRasterPath },
{ "out_polyline_features", contourPath },
{ "contour_interval", contourInterval },
};
var values = Geoprocessing.MakeValueArray(parameters.Values.ToArray());
var results = await Geoprocessing.ExecuteToolAsync("Contour_sa", values, null, progressor, GPExecuteToolFlags.None).ConfigureAwait(true);
if (results.ErrorCode != 0)
{
var messages = new StringBuilder("The Contour geoprocessing tool errored with the following messages:");
messages.AppendLine();
foreach (var message in results.ErrorMessages)
messages.AppendLine($" - {message.Text}");
throw new InvalidOperationException(messages.ToString());
}
}).ConfigureAwait(true);
}