We demonstrated how to Create AutoCAD .NET C# Addin in Visual Studio 2008 Using AcadNetAddinWizard (aka. AutoCAD .NET Addin Wizard) for various AutoCAD versions and language and discussed about the Versions of AutoCAD, .NET Framework Runtime, and Visual Studio.
As indicated in the table presented in the article, AutoCAD 2012 is built with .NET Framework Runtime 4.0 but the highest runtime that Visual Studio 2008 supports is 3.5. Nothing prevents us from creating an addin project for AutoCAD 2012 and automatically referencing the correct AutoCAD .NET API assemblies into the project using AcadNetAddinWizard running inside Visual Studio 2008, but something has to be tweaked a bit for sure afterwards as the .NET Framework Runtime version 3.5 is set up in the resultant project.
If the AutoCAD 2012 is intact regarding .NET Framework Runtime support and we are trying to launch AutoCAD from inside the debugger of Visual Studio 2008, an error will come up saying something like:
“Microsoft Visual Studio
Error while trying to run project: Unable to start program ‘C:\Program Files\Autodesk\AutoCAD 2012 – English\acad.exe’.
The debugger’s protocol is incompatible with the debuggee.”
Here is a screenshot about the message:
What’s going on here?
As mentioned earlier, AutoCAD 2012 is built with the .NET Framework Runtime 4.0 and forces its addins to use the same version as indicated in its configuration file, acad.exe.config:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
…
…
</configuration>
Commenting out the supportedRuntime line in the file and saving it back will allow the addins built with 3.5 version of .NET Framework Runtime to load and run. But when addins built really with the runtime version 4.0 are trying to be loaded, some other error messages will come up and/or AutoCAD does not recognize the assembly or its commands. So AutoCAD 2012 cannot load and run addins of runtime 3.5 and 4.0 versions side by side.
Who said DLL hell is gone away in the .NET world?
Doesn’t really matter.
So Visual Studio 2010 is strongly recommended for the development work for AutoCAD 2012. And AcadNetAddinWizard also supports this IDE seamlessly in a single installation. If by any means, this version is not available but Visual Studio 2008 is handy and it is still required to do some development for AutoCAD 2012, coding and debugging can still be done effectively in the development environment for sure through making the above tweak to the acad.exe.config.
However, in the deployment stage, it is definitely a good idea to rebuild the whole project using the free Visual C# Express 2010, for instance. When choose to do so, you may encounter another error as appended below after the project has been migrated automatically by the project loading and the .NET Framework Runtime version adjusted.
“Error 1 The type 'System.Windows.Markup.IUriContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral”
As suggested by the message, referencing the System.Xaml into the project resolves the problem right away.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) supports both Visual Studio 2008 and 2010 of both full-fledged and Express. And better, it references the appropriate AutoCAD .NET assemblies and set up the right .NET Framework Runtime version in the resultant project automatically when possible.
Recent Comments