Posted on 20. May 2010

RevitAddinUtility x32/x64

Jeremy nicely summed up the issues with the RevitAddUtility.dll . I thought I’d document my solution which uses interfaces to solve the issue. The problem is the loader exception fires before your application can catch it. By using interfaces you can utilise the appropriate assemblies which maintaining a single main application and no file copying.

Depending on which platform you run it on, the console app should utilise the correct assembly. In this example it just prints the names of any revit applications installed.

Here’s the console code for reference.

var assemDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var current = AppDomain.CurrentDomain;
IAddInFactory addinFactory;
try
{
    // assume 64bit is more common now
    var addInAssemName = AssemblyName.GetAssemblyName(Path.Combine(assemDir, @"Redbolts.AddIn.AddIn64Factory.dll")).FullName;
    addinFactory = (IAddInFactory)current.CreateInstanceAndUnwrap(addInAssemName,
        "Redbolts.AddIn.AddIn64Factory.AddInFactory", 
        false, BindingFlags.Default, null, null , null, null, null);
    Console.WriteLine("Successfully loaded 64bit OS version of RevitAddInUtility");
}
catch (Exception ex)
{
    addinFactory = (IAddInFactory)current.CreateInstanceFromAndUnwrap(Path.Combine(assemDir, @"OS32\Redbolts.AddIn.AddIn32Factory.dll"),
        "Redbolts.AddIn.AddIn32Factory.AddInFactory",
        false, BindingFlags.Default, null, null, null, null, null);
    Console.WriteLine("Successfully loaded 32bit OS version of RevitAddInUtility");
}
 
 
if (addinFactory!= null)
{
    Console.WriteLine(addinFactory.RevitInstalledApplications.Count());
    foreach (string revitInstalledApplication in addinFactory.RevitInstalledApplications)
    {
        Console.WriteLine(revitInstalledApplication);
    }
}
Console.ReadLine();

And here’s the example app (VS2010 solution) ExampleAddInConsole.zip (44.82 kb) enjoy!!

Comments are closed