Error reading in .shp file

Oct 27, 2010 at 4:56 PM

Hey all,

I'd like to echo the sentiments people have made by saying a massive thanks for making this code available, it really has been useful for me personally!

I do however have a question I was hoping someone could shed some like on. So, I'm testing some stuff using a number of .SHP files from

Most of these work OK, but I've an issue with this one specifically:

The app simply errors and isn't able to read in the data and display anything. I've had similar issues with other files, and I'm trying to understand whether the issue is simply that they are too large/complex for some reason, or if there is an issue with the file. Any help would be much appreciated.

Thanks in advance,


Oct 27, 2010 at 6:25 PM

Hi Paul,

Can you provide more details on what is happening in the code? Are you using the code sample from the home page of this project to load the shapefiles? If you are using it, do you have any entries in shapefileReader.Records collection after calling shapefileReader.Read()? Also, can you confirm that no exception is being thrown on Read?


Thank You,



Oct 27, 2010 at 6:45 PM

Fair point. Not provided much detail have I. I'm actually at home now and my VPN connection isn't playing ball with work. So I'll give an interim answer until then....

I've actually just checked out the whole trunch src and am purely running the SHP silverlight example included in the trunk solution. So, it's 100% the code in the repo at the moment, which works great for some SHP files, and then fails entirely for others. When debugging I was getting an exception thrown, but I can't remember off the top of my head where exactly. Will have to check details and post tomorrow, but maybe that information helps a little?

Thanks again for getting back to me so quickly, it's very much appreciated!

Nov 2, 2010 at 12:36 PM

Hi Vish,

My apologies for not getting back to you after your quick response. I've been able to look into it in more detail, and for the shape file I specifically linked to, this is the stack trace we're getting when it fails:

System.ArgumentOutOfRangeException was unhandled by user code  Message=Index and count must refer to a location within the buffer.Parameter name: bytes  StackTrace:       at System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)       at Vishcious.ArcGIS.SLContrib.ShapeFile.ReadAttributes(Stream stream)       at Vishcious.ArcGIS.SLContrib.ShapeFile.Read(FileInfo shapeFile, FileInfo dbfFile)       at SLMaps.ShapefileViewer.openFileDialog_Click(Object sender, RoutedEventArgs e)       at System.Windows.Controls.Primitives.ButtonBase.OnClick()       at System.Windows.Controls.Button.OnClick()       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)       at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)  InnerException: 

with the following values at runtime (on line 325 of ShapeFile.cs)

recordContent = {byte[0]}
currentIndex = 1
field.FieldLengthInBytes = 5

We do have a record count in the 50k range as well, so initially it would seem the SHP file isn't the issue, but I'm not sure.

For some of the other files we have, we're getting a different error that may simply be down to the format of the SHP file, but I may need to look into that some more first. However, if you have any advice on the issue above, that would be much appreciated. Thanks again.

May 20, 2014 at 10:41 AM
Edited May 20, 2014 at 10:41 AM
Hi pauldunlop,

Hope you are fine. I have added some code to read all types of shape files . Kindly, follow below link, extract and replace the attached folder instead of the old one in your solution.

Hope it helps.