Archive for the ‘Microsoft.NET’ Category

ESRI Releases the ArcGIS API Evaluator

October 3, 2008

This handy tool allows you to scan all of your ArcGIS .NET code and generate a complete set of API usage statistics.  This will reveal the DLL dependencies, version information and the number of calls made to all ESRI assemblies, interfaces and members.

Help improve the product
One of the most important features of this tool is that it allows you to send your API usage information directly to the ArcGIS Development Team.  Once received, this information will be used to:

1.    Better understand the APIs that our customers are using (most popular).
2.    Make improvements to focused areas of the SDK (documentation and samples).
3.    Make decisions for future API development projects.

API Evaluator Scenarios

Scenario I – Help improve the SDK
Scenario II – Improve your code
Scenario III – Deployment

Source: ESRI

A few reasons to give it a try
I’m sure you can think of many different uses for this tool, but in general, you can use this tool to:

1.    Determine the general API usage for larger or unknown code samples.
2.    Determine the licensing required to run an application.
3.    Locate redundant code sections and make improvements.
4.    Detect library dependencies to help with deployment scenarios.
5.    Detect .NET version dependencies.
6.    And most importantly, help improve the product (see below).

This will be definitely helpful for ESRI developers and also knows understand how best you make use of it.

Note this can be used with 9.2 .. Please click on here to read on ArcGIS Evaluator


ArcGIS Online Services????

August 15, 2008

I am trying to connect to some of the standard map services from ArcGIS online using ArcGIS Server . There were several issues encountered while do so. This is not an easy task. Though ESRI says connecting to their services are simple and direct.  It should be noted that atleast service pack 4 is necessary to connect using ArcMap client. Connecting server using “ArcGIS server internet connection” . Selecting an ArcGIS Server Internet data source implies that the client will use access an ArcGIS Server service through a Web service endpoint.

In a resource manager, when specifying the definition for an ArcGIS Server Internet connection, provide the URL for the server that contains the service, then select which service you want to view from the dropdown box.  If authentication is enabled on the site, enter a username, password and domain before connecting.  There were several borders to be crossed if you were working in secured environment. Crossing firewall, webserver authentication, identity issues.

Since ArcGIS Server Web services can also utilize authentication enabled on a Web server, multiple Internet data sources with different authentication credentials can be used within the same Web application.  Installation of arcgis server and post installation is cumbersome job. Especially web application post install is important.

I’ve come across this error (see figure) while connecting to the services. If any one has fair success in doing so please drop me an email. I have deleted ArcWebServices account and did Web Apps post install but no success. I guess there is an identity issue while connecting.

Any ideas will be highly appreciated!

Code Conversion

July 11, 2008

Many developers looking for sample code, most often we will get a sample in other language than we develop. Here is one link which may help for developers to convert between C# to VB.NET and vice versa in a single click.

There are certain points to noted after conversion like

  • Braces- in VB.NET we use () whereas in C# [ ]
  • Explicit conversion of ESRI Interfaces/Methods
  • C#.NET Version- Setting Create Ramp to True 

     IAlgorithmicColorRamp colorRamp    

          bool t = true;

          colorRamp.CreateRamp(out t);

  • Whereas VB.NET we simple use –> colorRamp.CreateRamp(True)     
  • Ending braces in C# has to done manually. variable.ToString() or enum.Next()
  • Collections need to be carefully analysed.
  • ….

ESRI Javascript API is FREE

June 20, 2008

The JavaScript API’s are not part of the ArcGIS Server installation, but are being made available (for FREE!) to any JavaScript developers out on the Web. You can start using them right now with your 9.3 RC1 ArcGIS Server.

They are available at:

The new resource centers have all of the downloads for the JavaScript API’s, Samples, SDK, and documentation.


Technology Migration ArcGIS Server 9.2 to 9.3

June 19, 2008

This post higlights some points on technology migration from ArcGIS Server 9.2 to 9.3. Some one might ask, “Hello ..dude..why do you want this so early ?”.  ArcGIS 9.3 is expected to release by this July. So this would be ideal period to discuss on this. This will be helpful for those who wants to develop new application in 9.3 or redevelop/migrate the existing 9.2 application or atleast curious to know about new features in 9.3.

Yet 9.2 Web ADF have not been explored fully, atleast by myself. Now 9.3 is almost ready. I guess 9.2 released in November 2006. With in 2 years ESRI came up with brand new 9.3.  Web ADF in 9.2 has been under lot of critiscm from several folks though used widely. The ADF learning path is bit hard, thats the naked truth thats the reason everyone hate using 9.2 atleast in .NET. On Other hand Java ADF in 9.2 seems good but lacks documentation. I have not heared much annoyance/comments with respect to java.  Server is not so easy as conventional IMS.  ArcGIS Server provides extensive functionalities than IMS product. It all depends on your requirement and bussiness needs.  Lets get into topic without further noise.

In General, 9.3 ADF built on the same framework in 9.2 with a number of technology and performance enhancements have been incorporated in 9.3 to provide comprehensive platform. The core object model has undergone minor (believe so) changes.  ADF (.NET) is hybrid platform- mix of server side and client side development enviroment. Basic web controls like Map, TOC and Overview has been re-engineered and scriptable now.

Your migration options depend on whether you built a Web ADF application using the Web Mapping Application template (includes applications generated by Manager) or you build a custom Web ADF application without the template.  Below matrix explains the possiblities to upgrade.

9.2 to 9.2 Migration

 Key points for developers:

  • Using ASP.NET partial postback pattern instead of client callback. If you might written lot of code for TOC, rendering by now controls will take care of all your needs. Even if required, it will be on client side
  • Customised Web ADF Javascript libraries. Night mare on Javascript is gone. Developer can get full details of script along with neat documentation.
  • Custom tasks uses partial post back
  • Shallow stateful pattern is no longer supported in 9.3.  Developers should be aware of this. Because adding/removing layers done thru pooled server objects using shallow stateful concepts. Here 9.3 HTTP hanlder (ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler) responsible for Map draw operations.
  • Understanding of REST or Javascript API is must.

Sailent features in 9.3 :

  1. Ready made utilities for migrating from 9.2
  2. ArcGIS JavaScript Extension for the Google Maps API
  3. ArcGIS JavaScript Extension for Virtual Earth
  4. Javascript is made public, documented, JSON based, and object oriented. Makes life easy for developer.  9.3 ADF will use JSON instead of XML for it’s communications between the client and server – this alone speeds things up ~30%
  5. Integration with other Javascript frameworks – like Dojo or ExtJS. This allows much more control over how the application looks and behaves.
  6. Improved Map Control, TOC and Overview control. Number of callbacks is reduced.
  7. The resource manager can be managed in Javascript, and has lots of configuration – i.e. layer aliases, fields to show, map tips etc.
  8. Results Viewer: bi-directional highlight. The task can have different results behavior (fields, map tips etc). Kudos!
  9. Additional web controls, additional AjaxExtenders – DockExtender, HoverExpandExtender (pin window type of thing)
  10. Use of HTTP Handlers used instead of pages so the page lifecycle is avoided, so it’s faster
  11. Blending at 9.2 used a single tiling scheme. At 9.3 each resource has it’s own tiling scheme, and the “blending has been massively improved”
  12. Javascript intellisense for Visual Studio 2008.
  13. Better templates and utility to convert previous version templates.
  14. Eliminated lots of callbacks, http handlers improve performance because the control tree is not re-created and destroyed
  15. Visual studio 2008 and .NET 3.5 framework supported
  16. Out-of-box printing tool and export using Adobe Acrobat Reader (PDF)
  17. ArcGIS Image Server is now an optional extension to ArcGIS Server
  18. Integration with Arc Web services
  19. ArcSDE is fully integrated with ArcGIS Server. SDE license bundled with Server.
  20. Windows Vista Support
  21. PostgreSQL support
  22. OGC specifications
  23. Much more…..

Hear the  Latest Podcasts on ArcGIS Server 9.3 from ESRI. CLICK HERE 

To summarise ArcGIS Server 9.3 seems improved much quality and performance wise.

  • Those who are new to Server and about to start development in 9.3 then donot look back web ADF at all.
  • If you are graduating from 9.2 and coming out of Web ADF then 9.3 REST/javascript API will be solace.
  • Are you about to migrate to 9.3 then look at both pros and cons. Don’t jump.

I thank fellow bloggers Dave, James Fee, Tom and others who helped me with valuable inputs. I dare to write this post because am NOT in beta evaluation. Hence people like me who look for similar information, this post may help. If there were any mistakes/omissions/additions or want of further details, please do comment or email me.

Error in AJAX Callback Function

June 17, 2008

Are you getting this below error in ArcGIS Server 9.3 when you are making Ajax Call within Callback function?

__pendingCallbacks[…].async’ is null or not an object

Here is a solution for resolving this issue (click on title) : problem-microsoft-jscript-runtime-error

VS2008 and ArcGIS 9.3

June 17, 2008

ESRI : “Visual Studio 2008 will be a fully supported development platform for working with the .NET, VC++, and C++ APIs at ArcGIS 9.3. However, at this time, we do not recommend installing VS2008 and working with the ArcGIS Engine Controls. Our tests have revealed a significant issue (NIM013454) that would prevent developers from successfully using Visual Studio 2008 to build ArcGIS controls-based applications with the Tech Preview version of ArcGIS 9.3. Additionally the installation of Visual Studio 2008 also affects the application exe’s compiled with Visual Studio 2005 so these exe’s will crash when displaying a control. Uninstalling Visual Studio 2008 does not resolve the issue. We are working on a solution to this issue; if testing proves successful, the fix will be included in the forthcoming Beta of the ArcGIS 9.3 release.”

Does any one know/tested whether this issue has been fixed in 9.3 Beta? . Please comment if you have an answer.

Coding Practices and list of Frequent Errors

June 3, 2008

 Coding Practices and list of Frequent Errors

We have recently concluded a project and project closure meeting is conducted in order to ascertains the views/experience of stake holders especially developers. The project was about customizing ArcMap with set of new commands and tools using Microsoft .NET Technology. The project was developed by the team of junior programmers (first time coders) lead by a senior developer.

I would like to come out with the list of frequent errors committed by programmers, missing validations and performance improvement ways. I have briefly discussed here. You can take this as a check list before start coding. There is no particular order followed in this list.

1. System.NullReferenceException – “Object reference not set to an instance of an object.”

This is the most frequently committed error by every developer. I would rate this error as an top rated one. You see people asking about this everywhere; about why are they getting this error. This error primarily occurred when coders are not seriously looking at the Objects created for the class. Below are a few common causes for this

Cause: You are trying to use a reference variable whose value is Nothing/Null.

• When the value is Nothing/null for the reference variable that means it is not actually holding a reference to an instance of any object.
• You either never assigned something to the variable, never created an instance of the value assigned to the variable
• You set the variable equal to Nothing/null manually, or you called a function that set the variable to Nothing/null for you.

I wish to highlight that there is a difference between C#. NET and VB.NET. In certain instances VB.NET code will compile whereas the C# even not allow do this. This is for generic cases for example accessing string.

C#.NET won’t compile

string a;
if (a.Length == 0)


Console.WriteLine (“Yes”);


VB.NET will compile
Dim a As String

If a.Length = 0 Then


End if

But, there will be case in ArcObjects like this.

pMxDoc = m_MxDoc
pMap = pMxDoc.FocusMap
pFeatureLayer = pMap.Layer(0)
Dim Test As String = pFeatureLayer.Name
pFeatureClass = pFeatureLayer.FeatureClass
pFeatureCursor = pFeatureClass.Search(Nothing, False)

pFeature = pFeatureCursor.NextFeature //Culprit is here

We have written code and tested several times works well. But, when Layer (0) doesn’t have any features its throws an ugly error. We may test the code several times with the contents while there were no features and trying the get the Feature object it explodes. This is one such sample.

There are ‘n’ numbers of ways to cause this error in ArcObjects. I always suggest to check whether object is not ‘Nothing’ or object reference is properly set. Give higher importance when dealing with objects particularly while using COM objects.

2. ‘Maximum open cursors exceeded’ or ‘Layer in Use- Maximum number of streams exceeded’

This is also another frequent error which developer does. The maximum cursors will be opened while loop through recordset.

Where: Looping through a recordset using IFeatureCursor may cause the above error:

Garbage collection takes care of releasing resources in managed code. This process is non-deterministic and will release resources at some undetermined time. In most cases this approach works fine, however in this situation it is necessary to mark the COM object as eligible for garbage collection so the resources will be released in a timely manner. i.e. Explicit release of COM Objects when once usage is completed.

You can get sample code and detail on clicking this.

3. Opening and Closing Database Connection using predefined Methods.

It is best practice to open and close database connection using separate common methods by passing its parameters. We have to use this method whenever we need to open/close DB connection. It is also advisable that we need to close the DB connection on ‘Finally’ block; this prevents keeping the connection open when error has occurred in method.

// Open Connection
// Do Something…..

Catch (Exception ex)
//Show Error Messages
//Release unwanted Objects
//Close DB connection

//Close DB Connection here as well…

4. Checking ArcObjects License using AoInitialize object

It is very important to check license availability of the application developed. Especially while using ESRI products understanding License Concepts is bit tough if you are novice. It is worth to give a reading on EDN about license on ESRI products.

Whenever we develop a project first and foremost requirement gathered is product/license used at client side. We have to ascertain the Product used along with Service Packs. As developer we may develop with product used at our organization. This brings greater conflict if you mismatched. Its strongly recommend you to use same product license and service similar to client environment. This will reduce major pain during deployment.

Here are other frequent errors which should be taken care of

5. Use of Feature Class names for all validation; avoid using layer name which may change at any course of time

6. Whenever updating (inserting) data in database in bulk use IFeatureBuffer/IRowBuffer interface for better performance.

7. Always use Try/Catch Block in each and every subroutine/method. This is MUST for any disciplined programmer. Otherwise it would be of hell later when you encounter errors at final stage.

8. IndexOutofRange/ ArrayBound Exception/Over Flow erros/InvalidCast Exception are few common errors can be avoided easily by taking little care while coding. Read OMD for better usage. Especially while using C#.NET casting objects is very vital. There is a performance difference between two ways of casting.

a. pFeatLayer = (IFeatureLayer)pLayer;
a. pFeatLayer = pLayer as IFeatureLayer ;

9. Use of proper collections plays huge role in performance e.g. ArrayList in place of HashTable . The hashtable is used to retrieve value using Key/Value pair whereas Arraylist to use to store the content that cannot be accessed at random. Usage of collection should be judicious. Note, key has to be unique while storing in hash tables otherwise throws an error. Determining which variable to store as key and which as value is paramount importance while retrieving. We often mismatch and take a long detour.

10. Providing proper Error Messages.

User doesn’t want detailed error message or stack trace, providing meaning full error message is very important. I suggest using resource files for doing this job. The usage of constants and providing simple, meaningful message makes application user friendly.

11. Use of proper Enumeration while using Collections- Enumeration, Dictionary etc

12. File Not Found/Read-Write Error.

Sometimes we need to write data in text/excel file,  we must check whether file exists or not at the specified path and then proceed further. At times file which we are about to write will be opened by others or shared, we have to handle such situations. Use of System.IO.Exception solves the issue. Here is an sample code in VB.NET

       pStreamWr= New StreamWriter(strFoldPath + “\” + abc + “.csv”)
        blnOpen = False
Catch ex As IOException
        MessageBox.Show(abc + “.csv file is already in use. Please close the file and click Ok.”)
        blnOpen = True
Catch ex As UnauthorizedAccessException
        MessageBox.Show(abc + “.csv file property is Read-only. Please change the file property and click Ok.”)
        blnOpen = True
End Try

13. Usage of Constants throughout the project helps managing application easier. For example Message Box title /Form Title have to constant through out the application, hence usage of application level constant will solve the issue. Using resource file will be handy and easier.

14. Editing Concepts:

When to use pooled vs. non-pooled objects in case of Web Application is another question which we come across often. General practice is if your edits are quick, and you do not need to have un-do / re-do type capabilities, you apply them against a pooled object.For example – if you just need to insert a point into a layer – collect the x, y and attribute information via your web front end, and then create the feature in one transaction. This will work with a pooled object just fine.
If you want to have a longer running edit session, where the save is not automatically committed back to the database, use a non-pooled object.

15. Avoid simple errors like – allowing users to type in Dropdown list, this is prevented setting appropriate property in the control; Form will be opened multiple times on clicking command has been avoided by setting as Modal.

These are some of the points which has brought out at this instance. Many of developers may use better coding practice to avoid these sorts of error, but these points will be useful for many who just begin coding. As I said in top of this post these are used as check list to avoid frequent errors. If this post helps please drop your comments/Suggestion, you may suggest few more points to this one.


ArcObjects Tutorial II: Add Command to Toolbar

May 23, 2008

Welcome to second walkthrough on adding custom ArcGIS component (command) to standard tool bar in ArcMap. We have successfully created custom command using C#; adding this command to ArcMap standard toolbar through ESRI IExtension.

 Tools & Language: Visual Studio 2005, C#.NET, ArcGIS 9.2

Manually we can add the command using ArcMap Tools–>Customize–>Click Command Tab, Choose the category and drag the command to toolbar. If we want to save this command permanently in ArcMap; use ‘Save In’ option to ‘Normal.mxt’ . The command will be saved on template.  

The purpose of this walkthrough is to add the custom command to ESRI toolbar programmatically.  ESRI has provided option to develop Application Extension inheriting ESRI IExtension. By inheriting IExtension class we can create our own extension and add the extension in categories manager. Applications loads extension AUTOMATICALLY on Startup. Life cycle of loading extension is a) Application starts b) Extension are loaded c) Document is loaded  d)  Document is closed e) Extensions are unloaded .

There are two types of extension they are Visible and Invisible (present walkthrough). Visible extension inherits IExtensionConfig and it will be added in Extension Manager Window. Looks like other ESRI extension along with its description.

Once you added this class, new class ‘ApplicationExtension1.cs’ will create by inheriting base class IExtension. This class contains functions to Register COM components (Register and UnRegister) and IExtension members like Extension name (Property-String) , Startup, Shutdown methods.

Our objective is to add the developed custom command to existing standard toolbar, i.e. whenever we open Map Document is opened, and command should be added in the toolbar. For achieving this, we have add delegate (IDocumentEvent_NewDocumentEventHandler) and pass a method to be fired on startup.

public void Startup(ref object initializationData)


           //m_application is ArcMap Application

            m_application = initializationData as IApplication;

            if (m_application == null)


                 IMxDocument pMxDoc;       

            // pMxDoc is ArcMap Map Document 

            pMxDoc = (IMxDocument)m_application.Document;          

 // Creating Event Handler with a Method ’onNewOpenDoc’          

((IDocumentEvents_Event)pMxDoc).NewDocument += new IDocumentEvents_NewDocumentEventHandler(OnNewOpenDoc);



private void OnNewOpenDoc()


ICommandBar pCmdBar; 

//Create two new UID objects from UID class

UID pUID = new UID();

UID pCommandUID=new UID(); 

//pUID value is ArcMap Standard ToolBar UID Value  taken from here


pUID.Value = “{5DEB1DB8-C2A9-11D1-B9A2-080009EE4E51}”; 

pCmdBar= ICommandBar)m_application.Document.CommandBars.Find(pUID, false, false); 


// pCommandUID value is custom command UID value found in the class //created


pCommandUID.Value = “{a657d37d-5cdd-4315-8866-87e389f2ffb8}”;

object index=0; 

// Note object called index is set to ‘0′; command will be added as first //command in toolbar 

pCmdBar.Add(pCommandUID,ref index); 


In ‘OnNewOpenDoc’ method we have to write code for adding the custom command to toolbar.  This method gets fired on opening every new ArcMap Instance.


Build and run the project. Now you can notice your custom command appeared as first item in a standard toolbar (make visible, if not) of ArcMap.   


I hope that this tutorial will be of much help to beginner who starts programming in ArcObjects. I will add some useful external links to this post. 



Attachment: extending-arcgisnet  PDF  

ArcObjects Tutorial I-Create Custom Command

May 21, 2008

This walkthrough from ESRI teaches how to create a custom command by inheriting from the ESRI BaseCommand class. Inheriting the BaseCommand allows you to create commands more quickly and simple than directly implementing the ICommand interface in ESRI.ArcGIS.SystemUI.

Here is a link to start with. If you are new to application development in .NET environment, you can take this sample as your first step. The walkthrough explains in both VB.NET and C# languages.

If anyone has any doubts or require help on this, please do write me.

Create a Commad by Inheriting from Base Command 

You may ask wheather we can create ESRI command/tool using Java?. The answer is YES, but not in a direct way. We have to compile jar to dll using other tools (eg. J-Integra). If you are serious java developer you can watch this ESRI thread for the possible approach.

ArcObjects Tutorial Part II: How to add command in tool bar