Author Topic: Autodesk.AutoCAD.Interop problem  (Read 10071 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
Autodesk.AutoCAD.Interop problem
« on: January 01, 2009, 01:53:56 PM »
Quote
"Could not load file or assembly 'Autodesk.AutoCAD.Interop, Version=17.2.0.0, Culture=neutral, PublicKeyToken=eed84259d7cbf30b' or one of its dependencies. The system cannot find the file specified.":"Autodesk.AutoCAD.Interop, Version=17.2.0.0, Culture=neutral, PublicKeyToken=eed84259d7cbf30b"}
I only have 2008 loaded at home, but have 2009 and 2008 loaded at work. Somehow after using this project at work then reloading it at home I have managed to get this error.
1) It's been removed and readded tons of times to no affect.
2) C:\Windows\assembly\GAC_MSIL\Autodesk.AutoCAD.Interop\17.1.51.0__eed84259d7cbf30b\Autodesk. is the correct path shown in the properties window when highlighting the AUTOcad reference.
3) There is no reference to Autodesk.AutoCAD.Interop, Version=17.2.0.0 in the registry but many references to Autodesk.AutoCAD.Interop\17.1.51.0.
4) I copied the 17.2.0.0 version from work by doing
if u want to view the structure of the GAC folder do the following
start > run > cmd
type : "cd\windows\assembly"
type: "attrib -r -h -s desktop.ini"
type: "ren desktop.ini desktop.bak"
now open the GAC folder normally in your explorer, and you can see the actual structure.
found herehttp://social.msdn.microsoft.com/en-US/profile/?user=johnpccd&referrer=http%3A//social.msdn.microsoft.com/Forums/en-US/netfxsetup/thread/83d662c4-03d4-40f6-a52e-466db5934b9d/
but it wont work at home as I have scumbag Vista won't allow you to do anything problems.


I am at a bit of a loss now, any help appreciated.

sinc

  • Guest
Re: Autodesk.AutoCAD.Interop problem
« Reply #1 on: January 01, 2009, 02:08:49 PM »
I haven't tried doing exactly what you're doing, but I've run into issues with my compiled DLLs running on a machine with only 2008, after installing 2009 on my development machine.

This sounds like it might be the same problem.  If so, you need to download the 2008 ObjectARX and link to the acmgd.dll and acdbmgd.dll in there, instead of the ones in the install directory.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Autodesk.AutoCAD.Interop problem
« Reply #2 on: January 01, 2009, 02:26:21 PM »
Thanks, I'll try that sinc.

Weird: if I open up cad and netload there is no problem, it's only when debugging from the Visual C# 2008 editor.

sinc

  • Guest
Re: Autodesk.AutoCAD.Interop problem
« Reply #3 on: January 01, 2009, 02:37:00 PM »
You should download the 2008 ObjectARX at work, too, and link to it there, too.

The way I usually see the problem is I compile a DLL, and I have 2008 and 2009 installed on my machine.  Then someone who only has 2008 tries to run the compiled DLL, it won't work for them.  I have to change the references in my project, to reference acmgd.dll and acdbmgd.dll in the ObjectARX 2008 kit, then I can compile DLLs that work for people who have only 2008 installed.

TonyT

  • Guest
Re: Autodesk.AutoCAD.Interop problem
« Reply #4 on: January 01, 2009, 09:30:02 PM »
Quote
"Could not load file or assembly 'Autodesk.AutoCAD.Interop, Version=17.2.0.0, Culture=neutral, PublicKeyToken=eed84259d7cbf30b' or one of its dependencies. The system cannot find the file specified.":"Autodesk.AutoCAD.Interop, Version=17.2.0.0, Culture=neutral, PublicKeyToken=eed84259d7cbf30b"}
I only have 2008 loaded at home, but have 2009 and 2008 loaded at work. Somehow after using this project at work then reloading it at home I have managed to get this error.
1) It's been removed and readded tons of times to no affect.
2) C:\Windows\assembly\GAC_MSIL\Autodesk.AutoCAD.Interop\17.1.51.0__eed84259d7cbf30b\Autodesk. is the correct path shown in the properties window when highlighting the AUTOcad reference.
3) There is no reference to Autodesk.AutoCAD.Interop, Version=17.2.0.0 in the registry but many references to Autodesk.AutoCAD.Interop\17.1.51.0.
4) I copied the 17.2.0.0 version from work by doing
if u want to view the structure of the GAC folder do the following
start > run > cmd
type : "cd\windows\assembly"
type: "attrib -r -h -s desktop.ini"
type: "ren desktop.ini desktop.bak"
now open the GAC folder normally in your explorer, and you can see the actual structure.
found herehttp://social.msdn.microsoft.com/en-US/profile/?user=johnpccd&referrer=http%3A//social.msdn.microsoft.com/Forums/en-US/netfxsetup/thread/83d662c4-03d4-40f6-a52e-466db5934b9d/
but it wont work at home as I have scumbag Vista won't allow you to do anything problems.


I am at a bit of a loss now, any help appreciated.


Well, this is the major reason I avoid referencing the COM interop assemblies like the plague, and for what little COM-related code I have that must access COM objects, I use late binding to access them (late binding will become much easier in CLR 4.0, btw).

The basic problem is that the COM assemblies are located in the GAC and they are the ones for the most recent product release. Because of that, the version you reference (the most recent product installed on your development system) must be on the target system. With COM assemblies, versioning works differently than it does with managed assemblies.

My guess is that if you need to deploy on AutoCAD 2008, you cannot develop with AutoCAD 2009 installed, because your project will reference the AutoCAD 2009 COM assemblies. The obvious solution is to avoid COM if possible, but if you are targeting a vertical like C3D, then that's not an option.

There may be ways around it (e.g., by copying the AutoCAD 2008 interop assemblies from the GAC, and then referencing them by their filenames), but I've never gone down that road myself.


Bryco

  • Water Moccasin
  • Posts: 1883
Re: Autodesk.AutoCAD.Interop problem
« Reply #5 on: January 03, 2009, 11:11:35 AM »
Sinc, It didn't work for me. I tried a few variations and besides the acmgd.dll and acdbmgd.dl there are 2 ways to reference interop in that folder , one of them reverts to the Gac folder somehow.
What did work for me was pasting the new version into the Gac and by using run->c:\windows\assembly\gac I could open the folder in windows explorer.

Tony, I am not sure how to avoid using interop, eg the following
Code: [Select]
interop.AcadApplication Ap= (interop.AcadApplication)acadApp.AcadApplication;
        interop.AcadPreferencesDrafting dprefs=Ap.Preferences.Drafting;
        dprefs.AutoSnapMagnet=true;
        dprefs.AutoSnapMarker=true;
and as I said the problem only occurs while debugging.




TonyT

  • Guest
Re: Autodesk.AutoCAD.Interop problem
« Reply #6 on: January 04, 2009, 07:42:33 AM »
Tony, I am not sure how to avoid using interop, eg the following
Code: [Select]
interop.AcadApplication Ap= (interop.AcadApplication)acadApp.AcadApplication;
        interop.AcadPreferencesDrafting dprefs=Ap.Preferences.Drafting;
        dprefs.AutoSnapMagnet=true;
        dprefs.AutoSnapMarker=true;

   and as I said the problem only occurs while debugging.


This is how I avoid referencing the COM Interop libraries:

Code: [Select]



// Helper class for invoking COM methods via late-binding (e.g., no type library reference)

public static class ComHelper
{
   public static object Invoke( object target, string method, params object[] args )
   {
      return target.GetType().InvokeMember( method, BindingFlags.InvokeMethod, null, target, args );
   }

   public static T Invoke<T>( object target, string method, params object[] args )
   {
      return (T) Invoke( target, method, args );
   }

   public static object GetProperty( object target, string property, params object[] indices )
   {
      return target.GetType().InvokeMember( property, BindingFlags.GetProperty, null, target, indices );
   }

   public static T GetProperty<T>( object target, string property, params object[] args )
   {
      return (T) Get( target, property, args );
   }

   public static void SetProperty( object target, string property, object value, params object[] indices )
   {
      object[] args = null;
      if( indices != null && indices.Length > 0 )
      {
         args = new object[indices.Length + 1];
         Array.ConstrainedCopy( indices, 0, args, 1, indices.Length );
         args[0] = value;
      }
      else
      {
         args = new object[] { value };
      }
      target.GetType().InvokeMember( property, BindingFlags.SetProperty, null, target, args );
   }

   // Like SetProperty(), but returns the current value for saving/restoring

   public static object GetAndSetProperty( object target, string property, object value, params object[] indices )
   {
      try
      {
         return Get( target, property, indices );
      }
      finally
      {
         Set( target, property, value, indices );
      }
   }
}

// Using the above:

using Acad = Autodesk.AutoCAD.ApplicationServices.Application

public class Example
{
   public SetPropertiesExample()
   {
      object drafting = ComHelper.GetProperty( Acad.Preferences, "Drafting" );
      ComHelper.SetProperty( drafting, "AutoSnapMagnet", true );
      ComHelper.SetProperty( drafting, "AutoSnapMarker", true );
      Marshal.ReleaseComObject( drafting );
   }
}




Bryco

  • Water Moccasin
  • Posts: 1883
Re: Autodesk.AutoCAD.Interop problem
« Reply #7 on: January 04, 2009, 02:43:59 PM »
I'll give that a go later, thanks Tony.
Excel is such a nightmare in vba without latebinding that I can see the point.  There's no doubt I'll end up using it.