Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In my C# Console Application, Visual Studio 2010 highlights new FeatureClassNameClass() in my below line of code and states "ESRI.ArcGIS.Geodatabase.FeatureClassNameClass has No constructors defined" and then states cannot be embedded. Use aplicable interface instead. How else can I define pOutFeatClassName as type IFeatureClassName?

IFeatureClassName pOutFeatClassName = new FeatureClassNameClass();

If I change the code to below, then Visual Studio does not throw an immediate error but once I run my application Visual Studio immediately bombs at this line and only states "error vshost32.exe". What is going on? Many Thanks for any suggestions..

IFeatureClassName pOutFeatClassName = (IFeatureClassName)new FeatureClassName();
share|improve this question
    
Thanks Exile79. You solved my issue. –  user17782 May 2 '13 at 16:43

2 Answers 2

up vote 2 down vote accepted

Are you initializing ?

This works for me:

class Program
{
    private static LicenseInitializer m_AOLicenseInitializer = new DesktopConsoleApplication1.LicenseInitializer();
    [STAThread()]
    static void Main(string[] args)
    {
        //ESRI License Initializer generated code.
        m_AOLicenseInitializer.InitializeApplication(
            new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeArcInfo },
            new esriLicenseExtensionCode[] { });

        try
        {
            IFeatureClassName fcn = new FeatureClassNameClass();
            ((IDatasetName)fcn).Name = "test";
            Console.WriteLine(((IDatasetName)fcn).Name);               
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
        }
        Console.WriteLine("press enter to close window");
        Console.ReadLine();

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

This LicenseInitializer code was created by the VS2010 project template for New arcgis console app:

internal partial class LicenseInitializer
{
    public LicenseInitializer()
    {
        ResolveBindingEvent += new EventHandler(BindingArcGISRuntime);
    }

    void BindingArcGISRuntime(object sender, EventArgs e)
    {
        //
        // TODO: Modify ArcGIS runtime binding code as needed
        //
        if (!RuntimeManager.Bind(ProductCode.Desktop))
        {
            // Failed to bind, announce and force exit
            Console.WriteLine("Invalid ArcGIS runtime binding. Application will shut down.");
            System.Environment.Exit(0);
        }
    }
}
share|improve this answer
    
Hi Kirk- above my Main I have private static IAoInitialize m_pAoInitialize; And in my Main I have IAoInitialize ao = new AoInitialize(); ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo); Is there any issue with the way I have setup my licenseInitializer? –  Josh Feb 3 '11 at 20:58
    
I'm able to go through other functions that use ArcObjects and I don't get an error there. But if I have not initialized my licenseinitialzer the best way then I need to –  Josh Feb 3 '11 at 21:00
    
If you are on arc10.0, you'll need to use the runtime binding. help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/… –  Kirk Kuykendall Feb 3 '11 at 21:43
    
Hi Kirk- I had forgot to include another line of my code where I do actually do the runtime binding so I believe I am doing that correctly. Besides, there are a number of other functions that use ArcObjects that I have no trouble on. Neil Clemmons on ESRI forums responded with an interesting response in the below link. I still don't understand why FeatureClassName has no constructor based on what he said but I will try to do what he suggests. Your thoughts? forums.arcgis.com/threads/… –  Josh Feb 7 '11 at 14:07
    
What happens if you create a new project (new arcgis console app) with references to necessary assemblies, then copy and paste the code I posted? –  Kirk Kuykendall Feb 7 '11 at 16:13

The solution:

  1. In your project references, find the assembly where FeatureClassNameClass is (ie ESRI.ArcGIS.Geodatabase).
  2. Right-click it and select "properties"
  3. Change "Embed interop types" to "false"

This 99% should do the trick

share|improve this answer
2  
+1 - came here from google and this solved my problem –  tbridge Jun 22 '11 at 22:35
    
Same here. This solved it perfectly for me. Don't know why this isn't the accepted answer –  Loko Jan 7 at 14:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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