We have a set of routines that have been used for writing rasters to the ArcMap table of contents from our tools. The code that always worked is this:
/// <summary>
/// Used for testing only. Do not execute this in published server code.
/// </summary>
/// <param name="rasterDataset"></param>
/// <param name="layerName"></param>
internal static void PutToMap(IGeoDataset rasterDataset, string layerName)
{
if (rasterDataset == null)
{
throw new ArgumentNullException("rasterDataset");
}
RasterLayer layer = new RasterLayer();
IApplication baseApp = (IApplication)Activator.CreateInstance(Type.GetTypeFromProgID("esriFramework.AppRef"));
IMxDocument doc = (IMxDocument)(baseApp.Document);
IMap activeMap = doc.ActiveView.FocusMap;
if (rasterDataset is Raster)
{
layer.CreateFromDataset(((IRaster2)(Raster)rasterDataset).RasterDataset);
}
else
{
layer.CreateFromDataset((RasterDataset) rasterDataset);
}
layer.Name = layerName;
layer.Visible = true;
activeMap.AddLayer(layer);
}
/// <summary>
/// Used for testing only. Do not execute this in published server code.
/// </summary>
/// <param name="layer">The raster layer or subclass that will be displayed</param>
/// <param name="layerName">The name to be put in the TOC</param>
internal static void PutToMap(IRasterLayer layer, string layerName)
{
IApplication baseApp = (IApplication)Activator.CreateInstance(Type.GetTypeFromProgID("esriFramework.AppRef"));
IMxDocument doc = (IMxDocument)(baseApp.Document);
IMap activeMap = doc.ActiveView.FocusMap;
layer.Name = layerName;
layer.Visible = true;
activeMap.AddLayer(layer);
}
internal static void PutToMap(IRaster raster, string layername)
{
IRasterLayer layer = new RasterLayerClass();
layer.CreateFromRaster(raster);
PutToMap(layer, layername);
}
We are now trying to debug a problem but when I try to write the cost raster out, these methods return an error when I try getting the singleton for ArcRef. The Activator.CreateInstance throws an exception in trying to load the module. Has anyone done this in 10.2.2 and is there a way to get things running that I'm missing???
I have tried changing the CreateInstance from Type.GetTypeFromProgID to Type.GetTypeFromCLSID and both approaches throws an exception. It returns an error of 8000ffff or something like that.