DependenciesSearchPaths problem. ( May I say a bug? )
Here is the situation :
I have two projects - the first is a simple AutoCAD 2012 plug-in ( .dll ) and the other is the same simple plug-in but for AutoCAD 2013. The two dlls are using the same source code - I link 2012 code into 2013 project - that is because Autodesk decided to move things around in the dlls - AcMgd.dll, AcDbMgd,dll, AcCui.dll in AutoCAD 2012 and one more in AutoCAD 2013 called AcCoreMgd.dll. The problem comes with a specific collection which is now in extension class.
At the end I have two projects in the same solution, the second just links the code of the firsts and has almost the same references. I ave two .saproj-ects too.
Where is the problem you should ask?
The problem is that I am building these two dlls in separate project files ( .saproj ) and when I try to obfuscate them the first project created gets done and the other does not. SmartAssembly displays an error :
SmartAssembly has encountered an invalid symbol
The most likely cause is that SmartAssembly has used a different version of dependency from the version used by acadPlugin2013.dll.
If the details below are wrong, please use the mandatoryPath attribute in the .saproj to ensure that the correct version of the dependency is found.
Assembly that should contain the symbol :
And surely it does display a good error message. Look back there - "objectArx.2012"!! - I have just made a brand new .saproj and selected object.arx.2013 folder not 2012 folder when I was prompted for the dependencies of my dll.
Where is the problem? - In the fact that SA writes its dependency search folders in "C:\ProgramData\Red Gate\SmartAssembly\SmartAssembly.settings" in the <DependenciesSearchPaths> section. Why is that a problem you should ask? Because this is not a per project section but a global section that sticks to SA and not the project. And why is that a problem? Because the firs project gets "instrumented" by SA with its assemblies and for the other I get the error because the associated assemblies are not its own but these from the previous project. Even I have selected different dependency during code analysis! Why is that? I thing it is because SA looks its search paths first and stops when it finds the .dll with the specified name. But that is the wrong dll. I am asking - Why is that behavior? Why SA prompts me for a dependency and then it gets its own from its search path?
And now SA finds the AcMgd.dll in the first folder, but we need the second folder, and brings it in and BANG - dependency error as displayed above.
"Have you tried setting "MandatoryPath" property in your 2013.saproj file in order to tell SA where to get the dependency explicitly as recommended by the error message?" - Yes, that was the first thing I have done as explained here http://www.red-gate.com/supportcenter/content/SmartAssembly/help/6.7/SA_SearchingForDependencies:
<Assembly AssemblyName="Acdbmgd, Culture=neutral, PublicKeyToken=null" MandatoryPath="..\..\..\libs\objectArx.2013\AcDbMgd.dll">
<Assembly AssemblyName="AcCui, Culture=neutral, PublicKeyToken=null" MandatoryPath="..\..\..\libs\objectArx.2013\AcCui.dll">
<Assembly AssemblyName="Acmgd, Culture=neutral, PublicKeyToken=null" MandatoryPath="..\..\..\libs\objectArx.2013\AcMgd.dll">
<Assembly AssemblyName="AdWindows, Culture=neutral, PublicKeyToken=null" MandatoryPath="..\..\..\libs\objectArx.2013\AdWindows">
<Assembly AssemblyName="AcTcMgd, Culture=neutral, PublicKeyToken=null" MandatoryPath="..\..\..\libs\objectArx.2013\AcTcMgd">
<Assembly AssemblyName="accoremgd, Culture=neutral, PublicKeyToken=null" MandatoryPath="..\..\..\libs\objectArx.2013\AcCoreMgd.dll">
Does it look good now? Yes, but there is something missing here - a fresh new restart of SmartAssembly. This is the point in the post when decided to try restarting it before posting. I needed to restart SA and not just edit it. I edited the .saproj, but it looks like it is in the memory of the application - body told me so, neither does the error message but I guessed it and everything runs runs now.
Why SA prompts me for the dependencies of my DLL in the beginning when the code analysis happens and when I point AcMgd.dll in objectarx.2013 folder everything is great and code analysis passes and after that when I press Build SA searches in its own prerecorded folders for my previous project and not the exactly selected DLL?
A good idea is to make the DependenciesSearchPaths attribute per project and not global in order to reduce "friction".
P.S. I really like SA and I admire the good work done on it. It saved me months in which I would have to reinvent the wheel.