.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autocad 2013 COM references

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Jeff_M
6504 Views, 9 Replies

Autocad 2013 COM references

WIth 2013's move to allow the use of Embed Interop Types, I thought it was going to help with different versions so we no longer had to reference the Interops in the ObjectARX folders (vs those listed in the GAC) when working with multiple versions. However, it appears when doing so I can no longer build a project on a 64 bit machine and have it run on a 32 bit machine. All calls to Acad* objects (AcadApplication, AcadDocument, etc.) fail with messages similar to this: 

 

Unable to cast COM object of type 'System.__ComObject' to interface type 'Autodesk.AutoCAD.Interop.AcadApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{070AA05D-DFC1-4E64-8379-432269B48B07}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Any ideas on how to get this to work with just one build?
Jeff_M, also a frequent Swamper
EESignature
9 REPLIES 9
Message 2 of 10
tomg
in reply to: Jeff_M

I only have 64 bit C3D2013 running.

 

Does the CSharpClient sample run on the 32 bit machine?

 

Tom

 

Message 3 of 10
Jeff_M
in reply to: tomg

Nope, nor does it work in the 64 bit version. All I did was copy the project to my VS2010 projects and build it. I will have to check the code to see if it's even trying to run correctly tonight. 

 

Thanks for the idea! I had been planning to create a small test project, this should save some time.

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 10
Jeff_M
in reply to: Jeff_M

Well, I was able to get CSharpClient.exe to run in x64 (the references were still pointing to 2012 GAC interops). However, it dies in the 32 bit environment just as my application does. Not what I was hoping to see.

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 10
tomg
in reply to: Jeff_M

Here's an excerpt from the C3D 2013 Readme:

 

**********************************

COM Interop Changes

 Interop DLLs are no longer registered as Primary Interop Assemblies (PIAs), and are deployed in the AutoCAD Civil 3D installation folder rather than the Global Assembly Cache (GAC). This means that these assemblies must now be added to Visual Studio projects using the Browse tab of the Add Reference dialog box, rather than from the COM tab as was done previously.

 To compile previously written projects against AutoCAD Civil 3D 2013, you will need to remove references to all interop assemblies from your project, and then re-add them using the Browse tab.

 The assemblies required for COM interop are:
 •Autodesk.AEC.Interop.Base
•Autodesk.AEC.Interop.UiBase
•Autodesk.AutoCAD.Interop
•Autodesk.AutoCAD.Interop.Common
•Autodesk.AECC.Interop.<domain>
•Autodesk.AECC.Interop.Ui<domain>

**********************************

 

These 6 interop assemblies are referenced in the CSharpClientSample app. Remove them and re-reference using the Browse tab (C3D installation folder). The runtime version for each is 4.0.xxxxx. On my machine it's 4.0.30319. Also, on my machine, none of these assemblies are in th GAC.

 

.NET 4.0 allows com assemblies to be embeded in the .NET application. Therefore the Embed Interop Types property should be set to True.

 

The CSharpClientSample Readme should have been rewritten to get rid of references to VC8 and VS2005. All you need is VS2010 set for C#. Also, the comment at the end of Form1.cs warning about closing AutoCAD while the app is still active does not seem to be true on my machine.

 

I've found a really great book (1712 pages):

 

Pro C# 2010 and the .NET 4 Platform by Andrew Troelsen.

 

It's a great reference for C# and the .NET 4 framework.The Index starts on page 1583 and runs to page 1712 which means you should be able to zero on any topic of interest. Best 40 bucks I ever spent.

 

Tom

 

Message 6 of 10
Jeff_M
in reply to: tomg

Thanks, Tom. I have followed those instruction to the letter, and it works fine on a 64 bit install when the dll is also built on a 64 bit machine. But it fails to work on a 32 bit install. I can take the same exact project, copy it to the 32 bit machine, rebuild it, and it works fine in the 32 bit C3D. But take THAT dll to a 64 bit machine and it fails in the exact same manner. Leading me to think we now need 2 separate builds for 32 & 64 bit machines....which is not what I wanted to hear.

Jeff_M, also a frequent Swamper
EESignature
Message 7 of 10
Jeff_M
in reply to: Jeff_M

For anyone wanting to check this out, I've attached a VS2010 C# project which demonstrates this issue. Built in Win7x64 it runs fine in C3D2013x64. Copy this dll to a 32bit machine and run C3D2013 there, it fails.  Copy the project to the 32bit machine, open in VS, rebuild, run C3D2013 and the command runs fine. Copy that dll to the x64 machine, run in C3D, failure.

 

This is the all that I have executing in this test:

    public class Class1
    {
        [CommandMethod("COMTest")]
        public void conmtest()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("\nAttempting to set AcadApplication object....");
            try
            {
                AcadApplication acadapp = (AcadApplication)Application.AcadApplication;
                ed.WriteMessage("\n....Success!");
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("\n.....FAILED! \n" + e.Message);
            }
        }
    }

 

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 10
tomg
in reply to: Jeff_M

Jeff,

 

Look at:

 

http://through-the-interface.typepad.com/through_the_interface/2012/03/migrating-net-applications-to...

 

In there you will find the following:

 

*****************************************************

 

Reply April 16, 2012 at 05:44 PM

 
MathewWebber said in reply to Maxence...

This is the same approach we take, although we have it worse as we support 2010, 2011, 2012 and now 2013. Oh and we have switches to build 64-bit and 32-bit versions of out plugin to suit the two versions

 

*****************************************************

 

What are the switches?

 

Tom

Message 9 of 10
Jeff_M
in reply to: tomg

Tom, THIS was posted yesterday which confirms the need for separate builds Smiley Mad Thanks for helping me look into this.

 

I'm guessing the switches mentioned are referring to something like the top response to THIS

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 10
tomg
in reply to: Jeff_M

Jeff,

 

My feeling all along was that you had to compile either to 32 bit or to 64 bit. I'm just getting iinto .NET. Was'nt sure if the .NET guys could produce a JIT compiler that could compile to either bitness base upon reading the machine OS info.

 

Good luck,

 

Tom

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost