Loading dxf from AutoCad 2016. A generic error occurred in GDI+.

Dec 23, 2015 at 1:03 PM

I have a problem with loading a dxf file created by AutoCad 2016. Even if I save it in earlier version (for example AutoCad 2010) netDxf do not load it and gives me en error:

A generic error occurred in GDI+

You can find example of file here:

Other dxf files, created by other (not AutoCad) software loads correctly.

What is wrong with this file?

Dec 23, 2015 at 5:08 PM
This seems to be the same kind of problem of the previous topic System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

I have not been able to reproduce this problem and I have been investigating it. It seems to be related with the access privileges of the system Fonts folder, when using a ttf font file from there to initialize a TextStyle, either creating a new one or during the loading process of an external dxf. The exception is thrown in the TextStyle constructor by the line:
It seems to affect Windows 8 but not 7, do not know about 10; and also ASP.NET web applications. At the moment I do not have a clear solution for it besides what cardinalwang proposed in System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+, or get the code and comment the whole if block in the TextStyle constructor:
if (Path.GetExtension(font).Equals(".ttf", StringComparison.OrdinalIgnoreCase))
     PrivateFontCollection privateFontCollection = new PrivateFontCollection();
     FontFamily[] fontFamilies = privateFontCollection.Families;
     string familyName = fontFamilies[0].Name;
     string registeredFileName = FontFileFromFamilyName(familyName);
     this.registered = !string.IsNullOrEmpty(registeredFileName);
     this.fontFamilyName = familyName;
It will not have serious side effects, if you even notice them at all, besides a mismatch with certain fonts when loading the file in AutoCad. All this was the result of trying to fix the problem exposed in TextStyle, but it seems it created a new one.

I will try to find another way to fill up the required information.

Dec 29, 2015 at 12:10 PM

Thank you for your help. It is not urgent so I will wait a while for solution or try to comment this piece of code.

I use Windows 10.

Jan 8, 2016 at 9:35 PM
Hola Daniel,
Primero ante todo quiero felicitarte por esta gran librería que has creado. Me está ayudando mucho en el proyecto que estoy desarrollando actualmente, muchas gracias!.

Por otro lado, también tengo el mismo problema mencionado en este topic. Utilizo windows 10.

He visto la solución de agregar el archivo ARIAL.TTF a la carpeta Debug y ha funcionado. Sin embargo mi aplicación tendría que distribuirla con el archivo ARIAL.TTF, no habría problemas de Copyright??

Has encontrado la solución para este problema?

Saludos y gracias.
Jan 9, 2016 at 3:23 PM
Puedes optar por la otra solución que indiqué un par de mensajes atrás, descárgate el código fuente y comenta el pedazo de código que se muestra en el constructor de la clase TextStyle.