As mentioned before, 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>
However, if the supportedRuntime line in the file has been commented out and we are trying to load an AutoCAD .NET addin built really with the version 4.0 of .NET Framework Runtime, what will happen?
Here it is:
“Cannot load assembly. Error details: System.BadImageFormatException: Could not load file or assembly
'file:///C:\Temp\AcadNetTest\bin\Debug\AcadNetTest.dll' or one of its dependencies. This assembly is
built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'file:///C:\Temp\AcadNetTest\bin\Debug\AcadNetTest.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
at loadmgd()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].”
The error message is pretty descriptive, and better, from both Autodesk and Microsoft!
As indicated by the message, adding the supportedRuntime version 4.0 back in the acad.exe.config file resolves the problem right away. It is unlikely that the problem will happen if you never touch on the acad.exe.config file but just in case this post may be a good reminder.
Once again, in the .NET world, the DLL hell does not really go away. Rather, a lot of new version concepts and mechanisms are introduced here and there and we have to exercise more care than before actually. All in all, checking the .NET Framework Runtime version that your AutoCAD .NET addins linked with and the .NET Framework Runtime version that the host AutoCAD really supports and make sure they match with each other is a critical matter. Such information has already been delivered in another article, Versions of AutoCAD, .NET Framework Runtime, and Visual Studio.
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 sets up the right .NET Framework Runtime version in the resultant project automatically when possible.
Recent Comments