Marshal.GetActiveObject Replacement in .NET 8+: Connecting to Running Autodesk Inventor Instances

<?xml encoding=”UTF-8″>by Chandra shekar Gopal,

As Autodesk Inventor continues evolving, developers targeting automation through its COM API face new challenges. One key issue is the deprecation of System.Runtime.InteropServices.Marshal.GetActiveObject in .NET Core and its obsolescence starting with Inventor 2025, which now supports .NET 8. This blog post focuses specifically on how to work with running Inventor instances in modern .NET environments using a reliable P/Invoke workaround.

⚠️ Note: Marshal.GetActiveObject was fully supported in Inventor 2024 and previous releases. However, Inventor 2025 officially supports .NET 8, making this method obsolete and unsupported. Developers must adopt alternative approaches for interacting with live Inventor sessions.


What Was Marshal.GetActiveObject in Inventor Automation?

In .NET Framework, Marshal.GetActiveObject("Inventor.Application") enabled developers to connect to a running instance of Autodesk Inventor. This capability was crucial for add-ins, scripts, or standalone tools automating tasks via Inventor’s COM API.

Unfortunately, .NET Core and .NET 5/6+ do not support this method. To continue developing automation tools with modern .NET runtimes, an alternative method is needed.


The Solution: Using P/Invoke to Access Inventor’s COM Object

Platform Invocation Services (P/Invoke) allow managed .NET code to call native Windows API functions. By importing COM interop functions directly, we can replicate the behavior of Marshal.GetActiveObject and connect to Inventor instances.

Sample Implementation

Here is a practical C# workaround that allows you to retrieve the active Inventor session in .NET Core or .NET 5/6/8:


using System;
using System.Runtime.InteropServices;
using System.Security;
namespace InventorInterop
{
internal static class NativeMethods
{
private const string OLEAUT32 = "oleaut32.dll";
private const string OLE32 = "ole32.dll";
[DllImport(OLE32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
public static extern void CLSIDFromProgIDEx([MarshalAs(UnmanagedType.LPWStr)] string progId, out Guid clsid);
[DllImport(OLE32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
public static extern void CLSIDFromProgID([MarshalAs(UnmanagedType.LPWStr)] string progId, out Guid clsid);
[DllImport(OLEAUT32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
public static extern void GetActiveObject(ref Guid rclsid, IntPtr reserved, [MarshalAs(UnmanagedType.Interface)] out object ppunk);
}
internal class InventorConnector
{
public static object GetInventorInstance()
{
Guid clsid;
string progId = "Inventor.Application";
try
{
NativeMethods.CLSIDFromProgIDEx(progId, out clsid);
}
catch
{
NativeMethods.CLSIDFromProgID(progId, out clsid);
}
NativeMethods.GetActiveObject(ref clsid, IntPtr.Zero, out var obj);
return obj;
}
}
}

Code Breakdown

NativeMethods Class:

  • Wraps required COM interop functions.
  • Includes methods for converting a ProgID to CLSID and accessing the Running Object Table (ROT).

InventorConnector Class:

  • Contains GetInventorInstance, a utility method specifically tailored to connect to Inventor.
  • Falls back to CLSIDFromProgID if CLSIDFromProgIDEx is unavailable.

Why This Matters for Inventor Developers

This workaround allows .NET Core and .NET 8+ developers to continue building powerful Inventor automation tools:

  • Ensures compatibility with Inventor 2025 and future releases.
  • Unlocks modern .NET features while maintaining access to the Inventor COM API.
  • Offers a robust template for other Autodesk automation scenarios.

Conclusion

With Inventor 2025 moving forward on .NET 8, legacy features like Marshal.GetActiveObject are no longer viable. Fortunately, by using P/Invoke to access native COM APIs, you can still attach to running Inventor instances and build effective automation workflows.

This method provides a future-proof way to maintain your productivity tools while aligning with Autodesk’s platform evolution.


Comments

4 responses to “Marshal.GetActiveObject Replacement in .NET 8+: Connecting to Running Autodesk Inventor Instances”

  1. Thank you so much!
    For more than one week I invest to find a solution and a workarround.
    May be you are so kind to set uo a small start program with forms and vb, so the visual studio solution can be used as “start up scaffolding”, consumed by older engineers like me

  2. Is there any public solution in visual studio for a small project with
    inventor 2025
    iLogic
    dll in .net8. with forms (Preferred in vb)
    Means a simple test.ipt with rectangular eg. 30 x 100 x 125, with ilogic and using a dll which do reading and save e.g. a
    iProperties.Value(“what you like”, “what you like”)
    ?

  3. Chandra shekar Gopal Avatar
    Chandra shekar Gopal

    Hi Juergen,
    Thank you for reaching out, and I appreciate your interest in a small Visual Studio project setup involving Inventor 2025, iLogic, and a .NET 8 DLL using VB.NET Forms.
    I understand this may be disappointing, but unfortunately, I’m not aware of any publicly available solution at this time that fits this exact setup — particularly one that includes a simple test.ipt part (e.g., 30x100x125 mm), integrates with iLogic, and communicates with a VB.NET DLL for reading and writing iProperties.
    Should such a reference project become available or if there’s an opportunity to develop a basic prototype, I’d be happy to keep you informed.
    Thanks again for your message.
    Best regards,
    Chandra Shekar G

  4. Hi Chandra,
    thanks for your kind reply.
    In the meantime I got by your and autodesk help the application running.
    As autodesk excample have small but significant failure, e.g As Property have to be As [Property] due related to a set.
    Also to configure Visual Studio with correct references is surly tricky and need a well structured tutorial, without no “small” forgotten parts as normally knowing by programmer… .
    However, thanks for your good article.
    Kind regards
    Juergen Gross

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading