English

Bug: Unhandled exception when ArcGIS Server or ArcIMS service is unavailable

Description

If an ArcGIS Server or ArcIMS service associated with a GIS resource is unavailable during initialization (e.g. initial page load), an error occurs. The exception message differs based on service type. For ArcGIS Server Internet, an HTTP 404 (Not Found) error code is returned. For ArcGIS Server Local, the message indicates that the server context was not started. For ArcIMS, the message indicates that there was an error reading the SERVICE_INFO response and return the code [ERR0134].

This issue applies to Web applications built with the ArcGIS Server Web ADF for the Microsoft .NET Framework.

Cause

Prior to 9.3 Service Pack 1, resources would fail silently and a Web ADF application would load, minus the resource. Numerous changes to the resource initialization process have been made between 9.3 final and Service Pack 1. While the fail-safe model is in place, some code paths in the new initialization process circumvent the model. For example, for ArcGIS Server services the initial call to return the MapResourceInternet.MapServerProxy property is not wrapped in a try\catch block to handle an exception, thus, if the service is unavailable and an exception occurs, the application stops. Some code logic should be used to evaluate the viability of the service during the initialization of the resource.

Workaround

Use the ResourceManager controls ResourceInit event to manually check the status of a service. Wrap the check in a try\catch and throw any exception that is returned. This works because the ResourceInit event is fired during resource initialization in the GISResourceItem class. If an exception is thrown, the fail-safe model is used to modify the resource appropriately. Use the following code as a guide (it works for both ArcGIS Server and ArcIMS):

C#

Code:
protected void Page_Init(object sender, EventArgs e)
{
MapResourceManager1.ResourceInit += new EventHandler(MapResourceManager1_ResourceInit);
}

void MapResourceManager1_ResourceInit(object sender, EventArgs e)
{
ResourceInitEventArgs resourceInitEventArgs = (ResourceInitEventArgs)e;

IMapResource mapResource = (IMapResource)resourceInitEventArgs.GISResourceItem.Resource;

if (mapResource == null) return;
try
{
IMapInformation mapInformation = mapResource.MapInformation;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Resource item " + resourceInitEventArgs.GISResourceItem.Name
+ " removed: " + ex.Message);
throw ex;
}
}


VB.NET

Code:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
AddHandler MapResourceManager1.ResourceInit, AddressOf MapResourceManager1_ResourceInit
End Sub

Private Sub MapResourceManager1_ResourceInit(ByVal sender As Object, ByVal e As EventArgs)
Dim resourceInitEventArgs As ResourceInitEventArgs = CType(e, ResourceInitEventArgs)

Dim mapResource As IMapResource = CType(resourceInitEventArgs.GISResourceItem.Resource, IMapResource)

If mapResource Is Nothing Then
Return
End If
Try
Dim mapInformation As IMapInformation = mapResource.MapInformation
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("Resource item " & resourceInitEventArgs.GISResourceItem.Name _
& " removed: " & ex.Message)
Throw ex
End Try
End Sub