As clearly shown in the table presented by the article Versions of AutoCAD, .NET Framework Runtime, and Visual Studio, AutoCAD 2011 internally built with the .NET Framework Runtime 3.5 and both Visual Studio 2008 and 2010 support targeting at it.
Therefore, we can use either to develop .NET addins for AutoCAD 2011.
However, if we create AutoCAD .NET addin projects manually, the .NET Framework Runtime target has to be paid some extra attention.
We can either switch the .NET Framework target from the default .NET Framework 4 to the wanted .NET Framework 3.5 for the Class Library project that is going to be created, which is essentially the AutoCAD .NET addin project type, by the Add New Project:
or switch the Target Framework property of the Class Library project manually from .NET Framework version 4 to 3.5 afterwards:
Otherwise, when the resultant AutoCAD .NET addin/assembly, even if it’s linked to the correct version of AutoCAD .NET API assemblies, is trying to be loaded into AutoCAD 2011, some messages are waiting there for us to know:
Command: netload
Cannot load assembly. Error details: System.BadImageFormatException: Could not
load file or assembly
'file:///C:\Temp\ClassLibrary1\bin\Debug\ClassLibrary1.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\ClassLibrary1\bin\Debug\ClassLibrary1.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 good thing is that the error messages are pretty descriptive, and better, from both Autodesk and Microsoft, and we can just follow the advice by re-linking the addin/assembly to the right version of .NET Framework Runtime to get rid of the problem; the bad thing is that something has to be done manually and we need to start all these over again, rebuilding, reloading and rerunning.
With the leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) handy, all these worries just go away and people can focus on the core coding right away. And better, AutoCAD 2007, 2008, 2009, 2010, 2011 and 2012, and .NET Framework Runtime 2.0, 3.0, 3.5 and 4.0 are all supported, correctly.
Posted by: |