haplokuon / netDxf

.net dxf Reader-Writer
MIT License
995 stars 405 forks source link

change assertions(that depend on user inputs) to exceptions if possible #335

Closed LeiYangGH closed 2 years ago

LeiYangGH commented 2 years ago

I got some dxf files that has some issues, but can open with cad viewer(entities can show, then a dialog prompts asking whether find dependent things). when open with netdxf assertion error prompt up and entire program cannot continue. I have many good files and some bad files, to find the bad ones, i use some code like this:

                foreach (string dxfFile in Directory.GetFiles(dir, "*.dxf", SearchOption.AllDirectories))
                {
                    try
                    {
                        DxfDocument doc = DxfDocument.Load(dxfFile);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(dxfFile );
                        Console.WriteLine(ex.Message);
                    }
                }

but assertion makes it impossible. assertfail

The bad file sample is attached. assertfail.zip

  1. Could the assertion be replaced with exceptions(return null DxfDocument is acceptable)?
  2. The same file in release mode can be loaded without error, is it safe to ignore the errors in release mode?
haplokuon commented 2 years ago

You should use the Release build of the library, the Debug build is not intended to be use by you, unless you want to get your hands dirty, it is for testing purposes only. I use assertions through the DXFReader to notify of bad data values in the file that were given a default value, and I want to keep track of them in case it has some side effect down the line. In your case your file contains multiple Style objects that has neither a font file nor font family information, so the default "simplex.shx" font file is used instead.

LeiYangGH commented 2 years ago

ok. thank you very much!