In the past C++/C era, it was very easy to crash AutoCAD or even the whole Operating System. Now in the .NET time, it is harder, much harder than before, but we still can find various ways to crash AutoCAD using its .NET API, from the easiest or most common to quite hard or very creative.
Now and then, we need to create side Database instances and operate on them such as creating a new DWG file and reading an existing one from disk into memory. However, if not carefully looking at things in detail, we may crash AutoCAD hard with a couple of very simple lines of code. We did so previously. Now let’s do it in a similar but still different way.
This time, let’s provide all false to the two arguments of the Database constructor.
[CommandMethod("Crash16")]
public static void Crash16_Method()
{
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Database db = new Database(false, false))
{
string dwgname = @"c:\temp\DatabaseCrash.dwg";
db.SaveAs(dwgname, DwgVersion.Current);
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.ToString());
}
}
After the assembly is loaded into AutoCAD and the command is run, an AutoCAD Error Aborting dialog saying ‘FATAL ERROR: Unhandled Access Violation Reading 0x0020 Exception at e2e3410dh’ would come up:
Note please that the memory address in the message may be different each time but the crash will not be missing.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides project wizards in C#, VB.NET and CLI/Managed C++, and various item wizards such as Event Handlers, Command/LispFunction Definers, and Entity/Draw Jiggers in both C# and VB.NET, to help program AutoCAD addins.
Recent Comments