7 Replies Latest reply on Nov 21, 2011 3:50 AM by gur.hanan

    What is the best syntax here??

    jvickrey79
      In my C# console application I tried using the below line of code to declare a IFeatureClassName object but Visual Studio 2010 says that FeatureClassNameClass() has No Constructors defined.  What??

      IFeatureClassName pOutFeatClassName = (IFeatureClassName)new FeatureClassNameClass();


      Also If I changed my code to the below line of code Visual Studio will not show any errors on the syntax but when I start debugging my application and I reach this line, Visual Studio throws a crazy error stating something like "error on vshost32.. and just stops debugging

      IFeatureClassName pOutFeatClassName = (IFeatureClassName)new FeatureClassName();


      Does anyone have any suggestions for me?  Thanks
        • Re: What is the best syntax here??
          Neil
          The error means that the FeatureClassName class does not have a public constructor, meaning that you cannot create a new instance of the class.  You obtain a reference to this type of object from another class which is capable of accessing the private constructor and returning an instance of the class to you.  In your particular case, one way to get the reference you're looking for is through IDataset.FullName.
          • Re: What is the best syntax here??
            vtammineni
            In my C# console application I tried using the below line of code to declare a IFeatureClassName object but Visual Studio 2010 says that FeatureClassNameClass() has No Constructors defined.  What??

            IFeatureClassName pOutFeatClassName = (IFeatureClassName)new FeatureClassNameClass();


            Also If I changed my code to the below line of code Visual Studio will not show any errors on the syntax but when I start debugging my application and I reach this line, Visual Studio throws a crazy error stating something like "error on vshost32.. and just stops debugging

            IFeatureClassName pOutFeatClassName = (IFeatureClassName)new FeatureClassName();


            Does anyone have any suggestions for me?  Thanks


            Use something like below

            IFeatureClassName pOutFeatClassName =  new FeatureClassNameClass();
            • Re: What is the best syntax here??
              jvickrey79
              Use something like below

              IFeatureClassName pOutFeatClassName =  new FeatureClassNameClass();


              I've tried that and I get two errors.  FeatureClassNameClass has no constructors defined and Interop type FeatureClassNameClass cannot be embedded so use the applicable interface instead.  Neil's suggestion makes sense although I still don't understand why FeatureClassName has no constructors defined.  I'll try to see if I can use Dataset.FullName instead.
              • Re: What is the best syntax here??
                jvickrey79
                The error means that the FeatureClassName class does not have a public constructor, meaning that you cannot create a new instance of the class.  You obtain a reference to this type of object from another class which is capable of accessing the private constructor and returning an instance of the class to you.  In your particular case, one way to get the reference you're looking for is through IDataset.FullName.


                Neil do you know how I can fix this issue on the FeatureClassNameClass object without using IDataset.FullName?  I'm not sure what has caused this.  Could a custom class be created that could get this working on FeatureClassNameClass?
                • Re: What is the best syntax here??
                  Neil
                  While there are classes in the ArcObjects model that you can't create yourself, it appears that the FeatureClassName class isn't one of them.  Your code should be fine.  Make sure you have all of the appropriate library references added to your project.  As far as I know, ESRI.ArcGIS.Geodatabase and ESRI.ArcGIS.System are required but there may be others (check the dev help).
                  • Re: What is the best syntax here??
                    vtammineni
                    I've tried that and I get two errors.  FeatureClassNameClass has no constructors defined and Interop type FeatureClassNameClass cannot be embedded so use the applicable interface instead.  Neil's suggestion makes sense although I still don't understand why FeatureClassName has no constructors defined.  I'll try to see if I can use Dataset.FullName instead.


                    Hi,

                    IFeatureClass is an interface..

                    http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IFeatureClassName_Interface/0025000002s3000000/

                    FeatureClassName is coclass..its a creatable class..

                    http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/FeatureClassNameClass_Class/0025000000ms000000/

                    Something like this...

                                   IFeatureClass inFeatureClass = (IFeatureClass)lName.Open();  
                                   IFeatureClassName inFeatureClassName = (IFeatureClassName)lName;  
                                   IFeatureClassName outFeatureClassName = new FeatureClassNameClass();  
                                   IDatasetName outDatasetName = (IDatasetName)outFeatureClassName; 
                                   IDataset outWorkspaceDataset = (IDataset)outWorkspace;  
                                    IWorkspaceName outWorkspaceName =                   (IWorkspaceName)outWorkspaceDataset.FullName;  
                                  outDatasetName.WorkspaceName = outWorkspaceName;
                    • Re: What is the best syntax here??
                      gur.hanan
                      Hi,
                      I had the same problem and I fixed it by changing the project "target framework" from 4.0 to 3.5 (in the application tab on the project properties).
                      Esri dose not support .Net framework 4.0 yet.
                      Gur