haplokuon / netDxf

.net dxf Reader-Writer
MIT License
1.01k stars 410 forks source link

Load Dxf file throw exception #386

Closed seppelhuang closed 1 year ago

seppelhuang commented 2 years ago

DxfDocument.Load(@"D:\1.dxf")

throw exception

Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: 0 at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at netDxf.Collections.ObservableDictionary2.Add(TKey key, TValue value) in E:\netDxf-master\netDxf\Collections\ObservableDictionary.cs:line 177 at netDxf.IO.DxfReader.BuildLayerStateManager() in E:\netDxf\IO\DxfReader.cs:line 11206 at netDxf.IO.DxfReader.ReadObjects() in E:\netDxf-master\netDxf\IO\DxfReader.cs:line 1118 at netDxf.IO.DxfReader.Read(Stream stream, IEnumerable1 supportFolders) in E:\netDxf-master\netDxf\IO\DxfReader.cs:line 295 at netDxf.DxfDocument.Load(String file, IEnumerable`1 supportFolders) in E:\netDxf-master\netDxf\DxfDocument.cs:line 529 at netDxf.DxfDocument.Load(String file) in E:\netDxf-master\netDxf\DxfDocument.cs:line 506 at TestDxfDocument.Program.Main() in E:\netDxf-master\TestDxfDocument\Program.cs:line 107

1.zip

haplokuon commented 2 years ago

Your problem is related with the layer states. For unknown reasons both layer states defined in your DXF contains three entries for the layer "0" properties which doesn't make much sense, there should be only one entry per layer. Anyways in the next update duplicate entries will be automatically removed. For the time being you can manually delete the duplicates from you original drawing.