views:

767

answers:

4

Hi everyone,

I am working on a custom tool for ArcGIS which will integrate with ArcView. The tool is developped using C# and basically connects to an SQL database, fetches data to a local data structure, performs a great deal of statistical analysis and then displays the results as a new layer.

The crash happens during this code's execution.

        LinkedList<SegmentDbRecord> segmentData = new LinkedList<SegmentDbRecord>();
        while( dataReader.Read() )
        {
            SegmentDbRecord record = new SegmentDbRecord();

            record.first_stop_id = dataReader.GetInt32(0);
            record.first_stopway = dataReader.GetString(1);
            record.first_stopway_X = dataReader.GetString(2);

            record.second_stop_id = dataReader.GetInt32(3);
            record.second_stopway = dataReader.GetString(4);
            record.second_stopway_X = dataReader.GetString(5);

            record.segment_start = Tools.timeToFloat((DateTime)dataReader.GetValue(6));
            record.segment_finish = Tools.timeToFloat((DateTime)dataReader.GetValue(7));

            record.stop1_long = dataReader.GetFloat(8);
            record.stop1_lat = dataReader.GetFloat(9);
            record.stop2_long = dataReader.GetFloat(10);
            record.stop2_lat = dataReader.GetFloat(11);

            record.max_speed = dataReader.GetInt32(12);
            record.avg_speed = dataReader.GetInt32(13);
            record.route_hnd = dataReader.GetInt32(14);
            record.seq_1 = dataReader.GetInt32(15);
            record.seq_2 = dataReader.GetInt32(16);
            record.route_name = dataReader.GetString(17);

            segmentData.AddFirst(record);

        }

At this stage, I'm just saving the query's results inside a linked list. I'm pretty sure the crash happens during memory allocation but I know there is still plenty of memory left and the query is not returning such a large dataset. Running a simple loop allocating new "records" also crashes very fast. Do any of you know of a built-in protection in the ArcGIS runtime that could prevent me from allocating more than a certain amount of memory ?

Thank you !

A: 

It could be a data conversion problem. Take for example the line:

record.max_speed = dataReader.GetInt32(12);
  • Is max_speed an int32?
  • Is the field in position 12 a value that can be converted to int32?

What you could do is to comment out all lines that allocate values, see if it runs, then add the lines back one at a time and see which one causes the error.

EDIT

Based on the comment looks like the problem is due to use of LinkedList. Why not just use List?

Shiraz Bhaiji
The problem still appears without the allocation code. Just allocating the memory and adding the records in the list suffice to crash the program.
Decapsuleur
Approximately how many records are you talking about here??
Ray Vernagus
I get the crash after having allocated 17969 records.That's around 1 MB of data.
Decapsuleur
Check the event log to see if the application pool is recycling
Shiraz Bhaiji
How could I check that ?Also, I get the same problem using List. I'm using a LinkedList because I wanted to avoid having to resize the array as it tends to be costly.
Decapsuleur
Go to administrative tools -> Event log and see if any errors are being written at the same time as you run the code. Do you have a text showing the exception being thrown?
Shiraz Bhaiji
A: 

ArcMap quietly swallows exceptions from user-added components. It's up to you to trap and handle any exceptions that occur in your code.

A simple troubleshooting technique consists of wrapping the entire code block in something like the following:

try {
    ... 
} catch (Exception ex) { 
    MessageBox.Show(ex.ToString());
    throw;
}

Hopefully you will get an informative message.

Ray Vernagus
No exceptions are thrown, unfortunately...
Decapsuleur
A: 

We had a similar mysterious crash issue with Arc GIS long time back. We eventually found that the disk quota was enabled in the server side, for the Arc GIS account. Removing the quota solved the issue.

Probably you can try that if anything else is not working.

amazedsaint
I'm not sure I understand which server you are talking about.
Decapsuleur
I believe amazedsaint is talking about ArcGIS Server, not ArcMap.
Ray Vernagus
Yep, the Arc GIS server
amazedsaint
A: 

The solution I found is to do all the processing in a different thread. The way my tool is structured, the button event was sending a command to a "Job handler" (let's call it that, I won't share my not-so-original internal class names) which was executing it right away (since no other work was scheduled). I think that since the memory allocation was taking too long, ArcGIS was considering the COM DLL as unresponsive and was handling the situation by simply crashing without any indication.

Thanks everyone for your always helpful answers.

Decapsuleur