1

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.

1 Answer 1

1

after a bit of work with a fellow geo programmer we found a workaround to this new ESRI issue.

Where we are creating and instance and casting it to IApplication, we now set the IApplication to this:

    /// <summary>
    /// This replaces the broken ESRI process of Activator.CreateInstance for AppRef
    /// </summary>
    /// <returns></returns>
    private static IApplication GetRunningObject()
    {
        IAppROT appRot = new AppROTClass(); 
        for (int index = 0; index < appRot.Count; index++)
        {
            if (appRot.get_Item(index) is ESRI.ArcGIS.Framework.AppRef)
                return (IApplication)appRot.get_Item(index);
        }
        return null;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.