I’m sure many of you who build a lot of standalone ArcObjects applications already know this, but I work mostly on server and mobile applications, and have never run into the problem.
Up until the release of ArcGIS 9.1, standalone ArcObjects applications initialized themselves with any available ArcGIS licenses, not requiring developers to explicitly grab a license when writing an ArcObjects application. This changed with 9.2, and the change was not very well-documented. I ran into this new ‘feature’ recently when trying to perform a simple connection to an SDE geodatabase. The code was very straightforward and compiled fine, and I couldn’t – for the life of me – figure out why it wouldn’t work. Then I ran into a couple of helpful posts on the ESRI support forums, which put me on the right track.
First, links to the posts:
- http://forums.esri.com/Thread.asp?c=93&f=993&t=205660&mc=7#msgid617799
- http://forums.esri.com/Thread.asp?c=159&f=1706&t=177817&mc=2
Now, a solution to the problem. In this example, I’m grabbing an ArcInfo license:
public void MainForm_Load(object sender, EventArgs e)
{
//Create new AoInitialize object, used in checking out/in ArcGIS license(s)
AoInitialize m_pAoInitialize = new AoInitialize();
//Try to initialize license
try
{
if (m_pAoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcInfo) == esriLicenseStatus.esriLicenseAvailable)
{
m_pAoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
}
else
{
MessageBox.Show("ArcInfo license not available. Check your network connection.");
}
}
//Catch any errors
catch (Exception exception)
{
MessageBox.Show("Error: " + exception);
}
}
Also make sure that you also shut down the AOInitialize object when you’re done with it. From the EDN documentation:
“Before an application is shut down the AOInitialize object must be shut down. This ensures that any ESRI libraries that have been used are unloaded in the correct order. Failure to do this may result in random crashes on exit due to the operating system unloading the libraries in the incorrect order.”
{ 2 comments… read them below or add one }
Hi,
I have been assigned the job of creating a standalone application on ARCOBJECTS using C#.net
What I want to know is, whether I can develop a standalone application on .net without using ArcEngine
I hope its a easy question to an experianced person like you
Please do.
I don’t have much familiarity with ArcEngine (and do not really develop desktop applications – this post was the results of a one-off prototype that I was building), but I’m pretty sure you can develop standalone applications without using ArcEngine. Just make sure you have Visual Studio installed and then install the .NET developer tools that come on the ArcGIS Desktop install DVD. You can then use Visual Studio to write your app.