Thanks to Fernando Malard for suggesting part of this topic in response to an issue he submitted through ADN support.
Windows applications that make use of the .NET Framework can be configured via a “.config” XML file found in their executable’s main directory (for more specifics, please see this MSDN article). In AutoCAD’s case, this file is called acad.exe.config, and is found in c:\Program Files\AutoCAD 2007 (for instance).
The default contents of this file for AutoCAD 2007 are:
<configuration>
<startup>
<!--We always use the latest version of the framework installed on the computer. If you
are having problems then explicitly specify .NET 2.0 by uncommenting the following line.
<supportedRuntime version="v2.0.50727"/>
-->
</startup>
</configuration>
This indicates a comment in an XML file: <!—this is a comment -->, so you can see that the “supportedRuntime” element is actually commented out. This means that AutoCAD will pick up the latest version of the .NET Framework on startup. There are circumstances where you might need to “downgrade” to a previous version of the .NET Framework. Here are a couple of examples of when this is needed:
- You install Visual Studio 2005 on your system but still wish to use Visual Studio 2003 to debug… VS 2005 installs the .NET Framework 2.0 and VS 2003 will not be able to debug applications using that version of the framework (see here for more details).
- You install Autodesk Map 3D 2007 side-by-side with Autodesk Map 3D 2006, and suddenly your Feature Data Objects (FDO) data sources no longer function. This is because Autodesk Map 3D 2007 installs the .NET Framework 2.0 but FDO in Map 3D 2006 apparently requires the .NET Framework 1.1 (see here for more details).
I think you see the pattern: a particular app has a requirement on a specific version of the framework (whether this was intended when it was built or not), and installing an application that uses a more recent version of the framework causes the first app to use this new version by default. Changing the “supportedRuntime” element to point to a specific version of the .NET Framework via its “version” attribute allows your first app to function as designed.
To specify the 2.0 version of the .NET Framework, use:
<supportedRuntime version="v2.0.50727"/>
And for the 1.1 version, use:
<supportedRuntime version="v1.1.4322"/>
Interestingly, there’s some other cool stuff that can be controlled via acad.exe.config (this is the piece that Fernando felt was worth sharing). As mentioned in this previous entry, there are sometimes issues with .NET modules being located outside of AutoCAD’s main executable folder. Aside from the ways already mentioned to avoid the issues, you can also make use of the “codeBase” element and the “probing” element in the acad.exe.config, to point AutoCAD to your various application folders.
Very simply, “codeBase” does the following (from MSDN): Specifies where the common language runtime can find an assembly.
<configuration>
<startup>
<!--We always use the latest version of the framework installed on the computer. If you
are having problems then explicitly specify .NET 2.0 by uncommenting the following line.
<supportedRuntime version="v2.0.50727"/>
-->
</startup>
<runtime>
<assemblyBinding>
<!-- one dependentAssembly per unique assembly name -->
<dependentAssembly>
<assemblyIdentity name="KeansModule" />
<!-- one codeBase per version -->
<codeBase version="1.0.0.0" href="file://C:/Program Files/Kean’s Company/Kean’s Application/KeansModule.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The “probing” element does something similar (from MSDN): Specifies application base subdirectories for the common language runtime to search when loading assemblies.
It seems, though, that this is not specific to particular assemblies, and so I'm guessing this might cause issues if multiple applications use it. For more information on the use of both “codeBase” and “probing”, see this .NET Framework Developer's Guide section on MSDN.