What is the best syntax here??

2124
7
02-03-2011 06:56 AM
JoshV
by
Occasional Contributor
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
0 Kudos
7 Replies
NeilClemmons
Regular Contributor III
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.
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
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();
0 Kudos
JoshV
by
Occasional Contributor
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.
0 Kudos
JoshV
by
Occasional Contributor
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?
0 Kudos
NeilClemmons
Regular Contributor III
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).
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
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_Interf...

FeatureClassName is coclass..its a creatable class..

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/FeatureClassNameClass_Cl...

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;
0 Kudos
gurhanan
New Contributor II
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
0 Kudos