Author Topic: COM issues with multiple versions of Civil 3D  (Read 2803 times)

0 Members and 1 Guest are viewing this topic.

sdunn

  • Newt
  • Posts: 90
COM issues with multiple versions of Civil 3D
« on: October 05, 2022, 03:04:22 PM »
I have a .net application that works with the survey database.  I have to use COM methods to access it. I have multiple versions of Civil 3D on my machine (2020 and 2022) and I am getting an error when other versions of Civil 3d are open and I try to run the command.  If a single version is opened, the command works as expected.  I use different .dlls (with the appropriate application versions) with each Civil 3d version used.

Code: [Select]
                If oAcadApp Is Nothing Then
                    oAcadApp = GetObject(, "AutoCAD.Application")
                    'get survey application
                    oAeccSurveyApp = oAcadApp.GetInterfaceObject("AeccXUiSurvey.AeccSurveyApplication.13.4")

                    If oAeccSurveyApp Is Nothing Then
                        ed.WriteMessage(vbCrLf + "Command must me run in Civil 3d. ")
                    Else
                        oAeccSurveyDB = oAeccSurveyApp.ActiveDocument.Database
                    End If
                End If



The error messages are:
Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
System.IO.FileNotFoundException: Problem in loading application
   at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
   at KHA.KHA.ExtractLineworkFromSurveyFigures2.cmdExtractFigureLinework()
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

and after the next run:
Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Autodesk.AutoCAD.Runtime.Interop.CheckNull(IntPtr returnValue)
   at Autodesk.AutoCAD.ApplicationServices.TransactionManager.StartTransaction()
   at KHA.KHA.ExtractLineworkFromSurveyFigures2.cmdExtractFigureLinework()
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()


Any help would be appreciated.

Thank you,
Stacy
 

n.yuan

  • Bull Frog
  • Posts: 348
Re: COM issues with multiple versions of Civil 3D
« Reply #1 on: October 06, 2022, 09:53:58 AM »
Since you did not show more code, such as how the object oAcadApp is declared, I assume you use early binding (e.g. has Acad COM Interop referenced), therefore your code is AutoCAD version dependent because of the COM early binding.

The catch here the this line:

oAcadApp = GetObject(, "AutoCAD.Application")

You should do

oAcadApp = GetObject (, "AutoCAD.Application.[version]").

The "AutoCAD.Application" class in the registry changes it class ID to the version of last AutoCAD session. If you have multiple version AutoCAD installed, you can see its change yourself by running different version of AutoCAD, and open the windows registry to see its class ID value.

Since you have to use COM for C3D survey data (I am with you for the pain Autodesk keeps there for so many years), you either make your code version dependent with COM early binding, or you can try late binding.
 

Jeff_M

  • King Gator
  • Posts: 4088
  • C3D user & customizer
Re: COM issues with multiple versions of Civil 3D
« Reply #2 on: October 10, 2022, 02:08:09 PM »
This process works in c# so would think it works in VB.NET as well:
oAcadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication


sdunn

  • Newt
  • Posts: 90
Re: COM issues with multiple versions of Civil 3D
« Reply #3 on: October 12, 2022, 06:15:50 PM »
Thank you for the advice.  I changed the code and it appears to work.

Code: [Select]
            Dim oAcadApp = Application.AcadApplication
            Dim oAeccSurveyApp As New AeccSurveyApplication()
            oAeccSurveyApp.Init(CType(Application.AcadApplication, IAcadApplication))
            Dim oAeccSurveyDB As AeccSurveyDatabase = CType(oAeccSurveyApp.ActiveDocument.Database, AeccSurveyDatabase)

It looks like I still need to change the COM references before building the application for another version of Civil 3D.  Is there any way around this?

Thank you,
Stacy

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: COM issues with multiple versions of Civil 3D
« Reply #4 on: October 12, 2022, 06:45:43 PM »
Thank you for the advice.  I changed the code and it appears to work.

Code: [Select]
            Dim oAcadApp = Application.AcadApplication
            Dim oAeccSurveyApp As New AeccSurveyApplication()
            oAeccSurveyApp.Init(CType(Application.AcadApplication, IAcadApplication))
            Dim oAeccSurveyDB As AeccSurveyDatabase = CType(oAeccSurveyApp.ActiveDocument.Database, AeccSurveyDatabase)

It looks like I still need to change the COM references before building the application for another version of Civil 3D.  Is there any way around this?

Thank you,
Stacy

Possibly, look into the dynamic keyword. in one application I was able to remove all COM references.
If you're doing a lot of code then it makes sense to create 'dynamic wrappers' because there's no intellisense in visual studio.
I used a test project with the com references along with the object browser to find the properties & methods 


https://www.theswamp.org/index.php?topic=55916.msg599242#msg599242