2

I am in a situation where I have Visual Studio installed on my work laptop but CATIA is installed on a remote machine. I am not allowed to have Visual Studio installed on the remote machine so my machine has no COM reference to CATIA. In VBA, I can simply use the code below to display the ActiveDocument's name developed on my work laptop and have it run on the remote machine without an issue.

Dim oCATIA as object
Dim oDoc as object
set oCATIA = GetObject(,"Catia.Application")
set oDoc = oCATIA.ActiveDocument
MsgBox oDoc.Name

I have trouble getting it worked with C# .NET, I learned that there is Dynamicmight be used but I don't know how to make this work.

    Type catiaType = Type.GetTypeFromProgID("Catia.Application"); //No issue
    dynamic oCatia = Activator.CreateInstance(catiaType); //No issue

    if((object)oCatia !=null)
    (
      dynamic oDoc = oCatia.ActiveDocument;   //Error
    )

I got what I believe very generic COM error message (0x800040005) Error HRESULT E_FAIL has been returned from a call to a COM component

3
  • If Catia is not open your oCatia is null? If Catia is not installed on remote machine your oCatia is null? In the future you will deploy this application to the machine where Catia is installed, right ? Commented May 29, 2023 at 16:33
  • @Disvoys, CATIA is there. That is why if I use VB.NET Framework 4.8 then I can get CATIA without any issue. Commented Sep 1, 2023 at 2:28
  • Did you figure it out? Although I try to avoid late-binding (see my answer for a strongly-typed alternative), I occasionally would like to use the 'dynamic' keyword. I have not managed so far. Have you? Commented Sep 8, 2024 at 18:34

1 Answer 1

0

Since R34 the dynamic keyword should work as advertised.

Otherwise another solution is to include a copy of the type libraries (.tlb) that ship with CATIA in your .NET project, and manually edit your project file to add a COMFileReference to the type libs. Visual Studio will produce the same interop glue code as if you were adding a regular COM Reference on a machine that has both VS and CATIA installed.

From there you can ditch the dynamic keyword, enjoy type safety, and your project will build without CATIA installed. Profit!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.