Life after .NET Framework - Late Binding

>TLDR Version Click Here<

Efficiency and streamlining are central to everything I do, both in work and in life. I’m always searching for ways to make workflows smoother, whether by simplifying a process, reducing unnecessary steps, or building tools that let us focus on what really matters. With the move away from .NET framework a years ago, the process of late binding has become a bit more cumbersome. Late binding provided a valuable tool for efficiency and was suddenly out of reach (at first), especially when working with large applications like Autodesk Inventor or Microsoft Office. Late binding had allowed developers to dynamically connect to these applications without fully loading them each time—making testing and debugging far quicker and more manageable.

To address this gap, I developed MercuryLateBinder.dll—a library designed to restore that lost flexibility in .NET and further enhance it. MercuryLateBinder.dll lets us connect to applications like Inventor and Office (or any COM-based software) dynamically using a search string, rather than relying on a fixed, hard-coded instance like "Inventor.Application". This approach means we can test and troubleshoot features without the need to load these applications in full each time, significantly speeding up the development cycle.

The goal of MercuryLateBinder.dll isn’t just to recreate lost functionality but to offer developers a way to work more smoothly and productively. By removing the wait times and allowing for more responsive testing, MercuryLateBinder.dll enables us to focus on building and refining solutions without the friction of loading times. For anyone who values streamlined, efficient workflows, this tool provides a way to get back to what’s important: creating and optimizing solutions with minimal interruption.


To Get Started:

- Download the MercuryLateBinder.zip package and extract it wherever you want to store it.

- in your project, right click References in your solution explorer and click "Add Reference"

- browse and select the MercuryLateBinder.dll file (in newer versions of Visual Studio the file appears under "Assemblies"

- ensure you that "Embed Interop Types" is set to no, "Copy Local" is set to yes

Your code to then late bind would be…

Autodesk Inventor:

        Dim app_InventorLateBound As Inventor.Application = MercuryLateBinder.BindingFunctions.LateBindToApp("Inventor.Application", MessagesReturnedFromDll, False, GetType(Inventor.Application)) 
        If IsNothing(app_InventorLateBound) = True Then '... (app wasn't found)

Microsoft Word:

        Dim app_WordLateBound As Word.Application = MercuryLateBinder.BindingFunctions.LateBindToApp("Word.Application", MessagesReturnedFromDll, False, GetType(Word.Application)) 
        If IsNothing(app_InventorLateBound) = True Then '... (app wasn't found)

Microsoft Excel:

        Dim app_ExcelLateBound As Excel.Application = MercuryLateBinder.BindingFunctions.LateBindToApp("Excel.Application", MessagesReturnedFromDll, False, GetType(Excel.Application)) 
        If IsNothing(app_InventorLateBound) = True Then '... (app wasn't found)

*Note: for Office applications, if you are getting an error regarding "Version not found ..." after setting "Embed Interop Types" is set to no & "Copy Local" is set to yes, then you need to add this to the app.config file to force the application to reference the latest version:

<configuration>

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="office" publicKeyToken="71e9bce111e9429c" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-15.0.0.0" newVersion="16.0.0.0" />

</dependentAssembly>

</assemblyBinding>

</runtime>

</configuration>

And if you can’t find your app.config file, you may have to add it as a new item.

Here’s a full example of the different ways to bind and how to list all your running processes:

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim MessagesReturnedFromDll As String = ""

        'to bind to and check the application type at the same time, specify the type of app that should be returned: GetType(Inventor.Application)
        'returns 1st application that has "Inventor.Application" in its name
        Dim app_InventorLateBound As Inventor.Application = MercuryLateBinder.BindingFunctions.LateBindToApp("Inventor.Application", MessagesReturnedFromDll, False, GetType(Inventor.Application)) 
        If IsNothing(app_InventorLateBound) = True Then
            'no application was found
            Console.WriteLine("A running instance of the application was not found with the given search term.")

            'you can get the list of all running applications using:
            Dim list_OpenApplicationsList As List(Of String) = MercuryLateBinder.BindingFunctions.ListAvailableRunningApps(MessagesReturnedFromDll)
           For Each str_OpenApplicationName As String In list_OpenApplicationsList
                Console.WriteLine(str_OpenApplicationName) 'entering any of these values as the search term in the "LateBindToApp(..." function will return that application object
           Next
           
           'you can also look at the "MessagesReturnedFromDll" string for more information
           Exit Sub
        End If

        'if you are running into errors when comparing types, leave the last part blank to return the app regardless of type (which you can then check later in the program)
          Dim boundedApplication As Object = MercuryLateBinder.BindingFunctions.LateBindToApp("Inventor.Application", MessagesReturnedFromDll) 'returns 1st application that has "Inventor.Application" in its name
	      If IsNothing(boundedApplication) = True Then Exit Sub 'no running instance containing the search term was found
	      Dim app_InventorFromTryCast As Inventor.Application = TryCast(boundedApplication, Inventor.Application)
	      If IsNothing(InventorFromTryCast) = True Then Exit Sub 'an application was found containing the search string but the Type of application is not Inventor.Application
     End Sub
End Class

TLDR Version (because I love efficiency!):

Late binding post .NET Framework can be cumbersome. I made this .dll to simplify the process and add some flexibility.

Developers add this DLL as a new reference to your project and you can late bind any COM interop using:

        Dim app_InventorLateBound As Inventor.Application = MercuryLateBinder.BindingFunctions.LateBindToApp("Inventor.Application", MessagesReturnedFromDll, False, GetType(Inventor.Application)) 
        If IsNothing(app_InventorLateBound) = True Then '... (app wasn't found)

You can have the DLL verify the application type before returning the application object (the last argument in the function but NOTE! make sure you use GetType(Inventor.Application) and not just Inventor.Application) or leave the argument blank and set your application variable to an object and verify afterwards.

Previous
Previous

Streamlining Autodesk Add-In Dev: A New Template for the Self-Taught