Author Topic: Error on accessing toolbars  (Read 3169 times)

0 Members and 1 Guest are viewing this topic.

sivag75

  • Guest
Error on accessing toolbars
« on: March 18, 2015, 02:37:59 AM »
Hi,
 
While I execute the second line in ACAD 2012, it throws an error as shown in the attached screenshot.
What could be the reason for this. However the same thing works in ACAD 2010 and 2011.
 
Code: [Select]
Dim toolbars As AcadToolbars
toolbars = Application.MenuGroups.item(0).Toolbars

The system details are:
XP - SP3
AutoCAD 2012
The program is compiled in Windows 7 with the target set as ' AnyCPU '.
The following dlls are used with CopyToLocal set as False.
AcDbMgd.dll
AcMgd.dll
AcCoreMgd.dll
Autodesk.AutoCAD.Interop.dll
Autodesk.AutoCAD.Interop.Common.dll
 
Please provide the solution.
 
Thanks
Regards,
gsktry

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Error on accessing toolbars
« Reply #1 on: March 18, 2015, 02:46:47 AM »
Are you sure you linked Interop assemblies from the same platform (inc-win32 or inc-x64) which has your AutoCAD (x86 or x64)? Also, I expect - you build your project as x86 or x64 instead of AnyCPU...

Oh, I see:
Quote
The program is compiled in Windows 7 with the target set as ' AnyCPU '.
this is wrong. When you use Interop, then you must compile as x86 and x64 instead of AnyCPU.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Error on accessing toolbars
« Reply #2 on: March 18, 2015, 02:55:21 AM »
I remember: Jeffrey Richter wrote the x86 and x64 assemblies has the same manifest. Their differences are located in IL-code. Therefore it is possible - to bind as reference assembly or x86 or x64 (it will the same). But when your program will work - it must to use the assemblies with according target platform.

Jeffrey wrote it about .Net Framework assemblies by Microsoft. I don't know is it correct for the Interop assemblies by Autodesk. I prefer to be reinsured and connect links from the corresponding catalog (inc-win32 or inc-x64).
« Last Edit: March 18, 2015, 03:05:34 AM by Andrey Bushman »

sivag75

  • Guest
Re: Error on accessing toolbars
« Reply #3 on: March 18, 2015, 03:08:20 AM »
Are you sure you linked Interop assemblies from the same platform (inc-win32 or inc-x64) which has your AutoCAD (x86 or x64)? Also, I expect - you build your project as x86 or x64 instead of AnyCPU...

Oh, I see:
Quote
The program is compiled in Windows 7 with the target set as ' AnyCPU '.
this is wrong. When you use Interop, then you must compile as x86 and x64 instead of AnyCPU.

Thanks for the quick reply. Actually, my program has to work in both XP and WIN7 systems with 32 & 64 bits. Do you mean that I need to compile and deliver separate dlls for each 32 and 64 bit versions ?
Suppose, if the client installs 32bit AutoCAD in WIN7 64 bit OS, which version of autocad DLL I have to give to them ? Please clarify.

Thanks
Regards,
gsktry

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Error on accessing toolbars
« Reply #4 on: March 18, 2015, 03:18:01 AM »
Do you mean that I need to compile and deliver separate dlls for each 32 and 64 bit versions ?
Suppose, if the client installs 32bit AutoCAD in WIN7 64 bit OS, which version of autocad DLL I have to give to them ? Please clarify.
Yes, you must compile your code as x86 and x64 separately when you use an Interop assemblies.
Suppose, if the client installs 32bit AutoCAD in WIN7 64 bit OS, which version of autocad DLL I have to give to them ? Please clarify.
As I know - you can not install AutoCAD x86 on Windows x64. In past, some vertical products by Autodesk, based on AutoCAD was x86 only and therefore can be installed on Windows x64 also. But if you use usual AutoCAD - then you can not install such AutoCAD x86 on Windows x64.

You can use the late binding instead of the Interop assemblies directly using . At this case it is possible to compile your project as AnyCPU.
« Last Edit: March 18, 2015, 03:21:09 AM by Andrey Bushman »

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Error on accessing toolbars
« Reply #5 on: March 18, 2015, 07:48:54 AM »
Look into Autodesk.Windows.ComponentManager and/or Autodesk.AutoCAD.Customization for a non COM solution.
« Last Edit: March 18, 2015, 07:54:21 AM by MexicanCustard »
Revit 2019, AMEP 2019 64bit Win 10

n.yuan

  • Bull Frog
  • Posts: 348
Re: Error on accessing toolbars
« Reply #6 on: March 18, 2015, 09:25:08 AM »
You say the code is for AutoCAD 2012, yet you listed reference to "accoremgd.dll", which is only available to AutoCAD2013 or later. Considering the error you get, I suspect that you somehow used the set of references (acdbmgd.dll/accoremgd.dll, acmgd.dll and the COM PIAs) from AutoCAD2013 or later, maybe downloaded from ObjectARX SDK for AutoCAD2013 or later.

Make sure you use these DLLs from ObjectARX SDK for AutoCAD2012 and try it again.

sivag75

  • Guest
Re: Error on accessing toolbars
« Reply #7 on: March 18, 2015, 12:28:00 PM »
Thanks Andrey. As you said, I removed the interop assemblies and changed the coding to late binding. The problem got solved now.

n.yuan : Sorry. I wrongly included  "accoremgd.dll" in my post. Actually it was not in my reference list.

Thanks
gsktry

n.yuan

  • Bull Frog
  • Posts: 348
Re: Error on accessing toolbars
« Reply #8 on: March 19, 2015, 09:17:14 AM »
... I removed the interop assemblies and changed the coding to late binding. The problem got solved now....

That is an indication that you possibly referenced wrong version of interop assemblies, likely a newer version than Acad2012