Wednesday 10 June 2015

arcobjects - No constructor defined?


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();

Answer



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);

}
}
}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...