I have a problem when trying to execute a model builder through C# the application throws:

an error has occurred error hresult e_fail has been returned from a call to a COM component

Note : ArcGIS 10.1 and .NET 2010


 using System;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geoprocessing;

namespace GeoprocessingInDotNet2008
    class Program
        private static LicenseInitializer m_AOLicenseInitializer = new GeoprocessingInDotNet2008.LicenseInitializer();

    static void Main(string[] args)
        // Load the product code and version to the version manager

        //ESRI License Initializer generated code.
        //m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeArcInfo },
        //new esriLicenseExtensionCode[] { });

        // Create geoprocessor. Overwrite true will replace existing output
        IGeoProcessor2 gp = new GeoProcessorClass();
        gp.OverwriteOutput = true;

        // Get the workspace from the user
        string wks = @"C:\Users\AmineMed\Documents\ArcGIS\LYDEC\DataBases";

        // set the workspace to the value user entered
        gp.SetEnvironmentValue("workspace", wks + "\\" + "Temp.mdb");

        // Add the custom toolbox to geoprocessor

        // Create a variant - data are in the workspace
        IVariantArray parameters = new VarArrayClass();
        parameters.Add(@"C:\Users\AmineMed\Desktop\mise à jour\El Mejjatya\Plan topo Al Wiam\Plan topo Al WiamT15071c.dwg");
        object sev = null;
            gp.Execute("Creation", parameters,null);
            Console.WriteLine(gp.GetMessages(ref sev));
        catch (Exception ex)
            string errorMsgs = gp.GetMessages(ref sev);
            Console.WriteLine("Hit Enter to quit");
            Console.ReadLine(); // pause the console to see messages

        //ESRI License Initializer generated code.
        //Do not make any call to ArcObjects after ShutDownApplication()

enter image description here


Use a try catch to fetch error messages from the gp object.

        GP.Execute("Creation", parameters, null);
    catch(exception ex)
| improve this answer | |
  • I tried this code but the message exception still the same – AmineMed Jul 2 '15 at 2:12
  • @AmineMed Did you try all message severity levels? I usually find something in there. What tool are you trying to run by the way? – pvdev Jul 2 '15 at 9:04
  • no I didn't. The tool I use is "DAO to Database" "Append" and "delete database" on one Model builder but I've already tried too just DAO to database but still no change. – AmineMed Jul 2 '15 at 9:42
  • NEED HELP PLEASE ! – AmineMed Jul 4 '15 at 2:05
  • @AmineMed I suspect that you would get more help by editing your question to make what you have tried and where you are stuck clearer. – PolyGeo Jul 13 '15 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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