Bug 5191:Shapefile to Shapefile- Conversion failed

Hi Alexander,

I moved to new version 26.5 and here my results:

Test data(input)
5191-Shapefile-Shapefile.zip (492.9 KB)

Error message :
[ShapefileTest] Testing Shapefile → Shapefile

Args: input=‘D:\GisConverter\Tests\Shapefile\Input\shapefile10.7z’, format=‘Shapefile’, output=‘D:\GisConverter\Tests\Shapefile\Output\2026-06-07_22-51-44\ShapefileTest\Shapefile’, temp=‘D:\GisConverter\Tests\Shapefile\Temp\2026-06-07_22-51-44\ShapefileTest\Shapefile’, logPath=‘D:\GisConverter\Tests\Shapefile\Log\2026-06-07_22-51-44\shapefiletest_shapefile_log.txt’, logLevel=‘’
:x: Conversion failed.
2026-06-07T22:51:46.6798779+03:00 (Local) | 2026-06-07T19:51:46.6798779Z (UTC)
Unexpected error: Length of the value exceeds length of the field.
Result: ConversionFailed

Hi Dani,

We’ve seen the “Length of the value exceeds length of the field” error when converting Shapefile → Shapefile with Aspose.GIS 26.5. It is raised when a record contains an attribute value longer than the field width defined in the source . Shapefile stores the field length in the .dbf header, and Aspose.GIS validates the data during write‑out.

Typical fixes

  1. Trim or truncate oversized strings before writing

    using Aspose.Gis;
    using Aspose.Gis.Shapefiles;
    using System.IO;
    
    // open source shapefile
    using (var src = Shapefile.OpenRead(@"D:\GisConverter\Tests\Shapefile\Input\shapefile10.7z"))
    // create destination shapefile
    using (var dst = Shapefile.Create(@"D:\GisConverter\Tests\Shapefile\Output\ShapefileResult.shp", src.Schema))
    {
        foreach (var feature in src)
        {
            var newFeature = dst.CreateFeature();
            // copy geometry
            newFeature.Geometry = feature.Geometry;
    
            // copy attributes, trimming string fields that exceed the defined length
            foreach (var field in src.Schema.Fields)
            {
                var value = feature[field.Name];
                if (value is string s && s.Length > field.Length)
                    s = s.Substring(0, field.Length); // truncate
                newFeature[field.Name] = s ?? value;
            }
    
            dst.AddFeature(newFeature);
        }
    }
    
  2. Increase field length in the destination schema (if you control the output structure)

    var schema = src.Schema.Clone();
    foreach (var field in schema.Fields)
    {
        if (field.DataType == FieldDataType.String && field.Length < 254)
            field.Length = 254; // maximum supported for Shapefile strings
    }
    using (var dst = Shapefile.Create(outputPath, schema)) { … }
    
  3. Use ShapefileWriterOptions to ignore length validation (available from 26.6 onward)

    var options = new ShapefileWriterOptions { IgnoreFieldLength = true };
    using (var dst = Shapefile.Create(outputPath, src.Schema, options)) { … }
    

What to check

  • Open the source .dbf (e.g., with a DBF viewer) and verify the declared lengths of string fields.
  • Ensure no attribute value exceeds those lengths; even a single long value will abort the whole conversion.
  • If the source file comes from an older GIS package, field lengths may be incorrectly set.

Next steps

  • Try the trimming approach above and see if the conversion succeeds.
  • If you need to preserve the full strings, recreate the destination schema with larger field sizes as shown.
  • Should the issue persist, please attach a small excerpt of the .dbf header (field names and lengths) or a sample feature that triggers the error. That will help us reproduce the problem and verify whether it’s a regression in the 26.5 build.

For further details you can also refer to the official docs: https://docs.aspose.com/gis/net/working-with-shapefiles/ and the API reference for ShapefileWriterOptions.

Let us know how it goes or provide the additional data, and we’ll continue troubleshooting.

Waiting to your answer. Thank you.

Hi, @danies8
We already discussed this issue before.
Please, don’t create duplicate bugs and check data first.

Shapefile based on dbf have restriction for field length.

Please close it:)
Thank you:)

Good.
I close this topic