1

I am trying to learn Arcobject with C# through a book named "begining arcgis desktop using dotnet" , in this book an example is given to use geoprocesisng tool to be used through arcobject.

below in the code

IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
IMap map = mxdoc.FocusMap;
if (map.Layer[0] == null)
{ return; }
ILayer layer = map.Layer[0];
IDataset dataset = layer as IDataset;
IGeoProcessor2 gp = new GeoProcessorClass();
gp.AddOutputsToMap = true;
gp.OverwriteOutput = true;
//syntax of the tool from tool's reference page
//MultipleRingBuffer_analysis (Input_Features, Output_Feature_class, Distances,
//{Buffer_Unit}, {Field_Name}, {Dissolve_Option}, {Outside_Polygons_Only})
IVariantArray parameters = new VarArrayClass();
//Input_Features
parameters.Add(layer);
//Output_Feature_class
parameters.Add(dataset.BrowseName + "MRB");
//you have to use ; to separate the distances (multivalue)
parameters.Add("10;50;100");
//{Buffer_Unit}
parameters.Add("kilometers");
//{Field_Name}
parameters.Add("");
//{Dissolve_Option}
parameters.Add("ALL");
gp.Execute("MultipleRingBuffer_analysis", parameters, null);
object severity = null;
MessageBox.Show(gp.GetMessages(ref severity));

it throws an error of "An unhandled exception of type 'System.AccessViolationException' occurred in GeoprocessingProject.dll"

i am new to dot net. can some body help to resolve this error ?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 19, 2016 at 8:09

1 Answer 1

2

I think the problem is your output. If you look at the help for this tool the syntax section clearly states the output is a FEATURECLASS.

You are providing a string which is the browse name + "MRB", so if your dataset you are buffering was called city then the output name is cityMRB. As you can see from my example your string does not say where to create this dataset. You would need to set the output workspace or provide a full path. Based upon the name I assume it is a geodatabase featureclass so what you should be supplying is a full path such as "C:\temp\mygeo.mdb\cityMRB"

I suspect the error is occurring because of that and it's defaulting to some location which is not creating a valid output FEATURECLASS name?

answered Jun 19, 2016 at 18:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.