nhilson
nhilson

Reputation: 55

"Failed to initialize the [add-in name] because the assembly [path to an add-in DLL file] does not exist" when launching Revit

I've exhausted every resource possible and can not figure out what the issue is. Button images won't show & keep getting this message when I try to use the command.

Failed to initialize the [add-in name] because the assembly [path to an add-in DLL file] does not exist

when launching Revit. Here's my code that I'm using.

   #region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.CSharp;
using System.Media;
using System.Reflection;
using System.IO.Packaging;
using System.Windows.Media.Imaging;
using System.Drawing.Imaging;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.Architecture;
#endregion

namespace TpMechanical
{
    internal class App : IExternalApplication
    {
        public Result OnStartup(UIControlledApplication a)
        {
            String tabname = "TpMechanical";
            String panelname = "Tools";

            //Option 1

            BitmapImage b1Image = (System.Windows.Media.Imaging.BitmapImage)TpMechanical.Properties.Resources.ResourceManager.GetObject("_design3_fhY_icon.ico");
            BitmapImage b2Image = (System.Windows.Media.Imaging.BitmapImage)TpMechanical.Properties.Resources.ResourceManager.GetObject("_design3_fhY_icon.ico");
            BitmapImage b3Image = (System.Windows.Media.Imaging.BitmapImage)TpMechanical.Properties.Resources.ResourceManager.GetObject("_design3_fhY_icon.ico");

            //Option 2 

            //Bitmap b1Image = (System.Drawing.Bitmap)(TpMechanical.Properties.Resources.ResourceManager.GetObject("Icon1.ico"));
            //Bitmap b2Image = (System.Drawing.Bitmap)(TpMechanical.Properties.Resources.ResourceManager.GetObject("Image1.jpg"));
            //Bitmap b3Image = (System.Drawing.Bitmap)(TpMechanical.Properties.Resources.ResourceManager.GetObject("Image2.bmp"));

            //Option 3 

            //BitmapImage b1Image = new BitmapImage(new Uri("pack:application:,,,/TpMechanical/Resources/Icon1.ico"));
            //BitmapImage b2Image = new BitmapImage(new Uri("pack:application:,,,/TpMechanical/Resources/Image1.jpg"));
            //BitmapImage b3Image = new BitmapImage(new Uri("pack:application:,,,/TpMechanical/Resources/Image2.bmp"));



            a.CreateRibbonTab(tabname);
            var Tools = a.CreateRibbonPanel(tabname, panelname);
            var button1 = new PushButtonData("TpButton1", "Button1", Assembly.GetExecutingAssembly().Location, "TpMechanical.command");
            button1.ToolTip = " This is a short description";
            button1.LongDescription = "This is a long description \n " +
                "this is the second line";
            var btn1 = Tools.AddItem(button1);
            button1.Image = b1Image; 

            var button2 = new PushButtonData("TpButton2", "Button2", Assembly.GetExecutingAssembly().Location, "TpMechanical.command2");
            button2.ToolTip = " This is a short description";
            button2.LongDescription = "This is a long description \n " +
                "this is the second line";
            button2.Image = b2Image;
   
            var button3 = new PushButtonData("TpButton3", "Button3", Assembly.GetExecutingAssembly().Location, "TpMechanical.command3");
            button3.ToolTip = " This is a short description";
            button3.LongDescription = "This is a long description \n " +
                "this is the second line";
            button3.Image = b3Image;
            
            Tools.AddStackedItems(button2, button3);
            

            return Result.Succeeded;
        }

        public Result OnShutdown(UIControlledApplication a)
        {
            return Result.Succeeded;

        }

    }
}

I also have my manifest code below.

 <?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Command">
    <Text>Command TpMechanical</Text>
    <Description>Some description for TpMechanical</Description>
    <VisibilityMode>AlwaysVisible</VisibilityMode>
    <Assembly>C:\My Revit- Custom Files\01-Revit 2021\Revit 2021 Repos\TpMechanical\bin\Debug\TpMechanical.dll</Assembly>
    <FullClassName>TpMechanical.Command</FullClassName>
    <ClientId>9EDCBEA6-942A-4D9A-932D-612B5E02DC9C</ClientId>
    <VendorId>com.typepad.thebuildingcoder</VendorId>
    <VendorDescription>The Building Coder, http://thebuildingcoder.typepad.com</VendorDescription>
  </AddIn>
  <AddIn Type="Command">
    <Text>Command TpMechanical</Text>
    <Description>Some description for TpMechanical</Description>
    <VisibilityMode>AlwaysVisible</VisibilityMode>
    <Assembly>C:\My Revit- Custom Files\01-Revit 2021\Revit 2021 Repos\TpMechanical\bin\Debug\TpMechanical.dll</Assembly>
    <FullClassName>TpMechanical.Command2</FullClassName>
    <ClientId>1A164A1B-8B02-499A-8ADB-94A75557CD66</ClientId>
    <VendorId>com.typepad.thebuildingcoder</VendorId>
    <VendorDescription>The Building Coder, http://thebuildingcoder.typepad.com</VendorDescription>
  </AddIn>
  <AddIn Type="Command">
    <Text>Command TpMechanical</Text>
    <Description>Some description for TpMechanical</Description>
    <VisibilityMode>AlwaysVisible</VisibilityMode>
    <Assembly>C:\My Revit- Custom Files\01-Revit 2021\Revit 2021 Repos\TpMechanical\bin\Debug\TpMechanical.dll</Assembly>
    <FullClassName>TpMechanical.Command3</FullClassName>
    <ClientId>C5CEC594-E407-40A8-B1B0-163DAA179CDD</ClientId>
    <VendorId>com.typepad.thebuildingcoder</VendorId>
    <VendorDescription>The Building Coder, http://thebuildingcoder.typepad.com</VendorDescription>
  </AddIn>
  <AddIn Type="Application">
    <Name>Application TpMechanical</Name>
    <Assembly>C:\My Revit- Custom Files\01-Revit 2021\Revit 2021 Repos\TpMechanical\bin\Debug\TpMechanical.dll</Assembly>
    <FullClassName>TpMechanical.App</FullClassName>
    <ClientId>C12635D2-96E2-4DF4-B172-7BD9487F7AE9</ClientId>
    <VendorId>com.typepad.thebuildingcoder</VendorId>
    <VendorDescription>The Building Coder, http://thebuildingcoder.typepad.com</VendorDescription>
  </AddIn>
</RevitAddIns>

enter image description here

Upvotes: 0

Views: 3086

Answers (3)

Jeremy Tammik
Jeremy Tammik

Reputation: 8294

Rereading your question a third time over, it sounds as if your add-in is trying to reference a .NET assembly DLL that cannot be found when Revit tries to load it. Looking at the list of namespaces that you reference in your source code using statements, I see nothing but standard Autodesk Revit, Microsoft and .NET assemblies listed. So, they should all be present and accessible. Are you using anything else elsewhere in your code that is not obvious from that list? You might be able to use tools like fuslogv to analyse your add-in dependencies during load time, as suggested in the note on Exploring Assembly Reference DLL Hell with Fuslogvw.

Upvotes: 2

Jeremy Tammik
Jeremy Tammik

Reputation: 8294

I am being inundated with similar questions these days. Here is another similar one, a summary of a recent email thread:

[Q] I have dived into the Getting Started with Revit platform API, following the DevTV tutorial by Augusto Goncalves. None of my commands appear on the Revit UI > Add Ins > external commands.

[A] One thing you ought to read is the introductory section of the Revit API developers guide. It tells you exactly what to do to install and launch your add-in. It is shocking of that information is not clear and does not work in the tutorial, though. Thank you for bringing it up!

Installing a Revit add-in is really simple, but people run into difficulties like you describe anyway.

There are only two relevant components:

  • Add-in manifest file *.addin
  • .NET class library assembly DLL

These are the important steps:

  • The DLL must implement IExternalCommand; that means, it must implement the Execute method.
  • The add-in manifest must point to the DLL and must be placed in the Revit Add-Ins folder for Revit to find and load it.
  • If the DLL and add-in manifest both reside in the Revit AddIns folder, the full DLL path can be omitted; otherwise it must be specified.

That is really all.

There are thousands of places explaining it; they all say the same thing.

Good luck and lots of fun with the Revit API :-)

[R] I have not had any luck since yesterday about my add-in not appearing in the Revit external commands.

I have carefully structured my code correctly. The add-in manifest file is pointing to my project .dll file. My project class explicitly implements the IExternalCommand interface and fires up the Execute method just fine.

I don't understand what the issue could be, not sure it could be the revit version am using am trying to figure out all possibilities.

[R2] I managed to debug my code. Kindly, ignore previous message.

The location of my manifest add-in file was locked. I guess that was done when my account was set up. The location needed permission to be accessed. This path:

  • C:\ProgramData\Autodesk\Revit\Addins\2022\

I utilised the try and catch exception to see the issue.

Once I gave access permission, the add-in file is now visible; it worked!

Upvotes: 0

Jeremy Tammik
Jeremy Tammik

Reputation: 8294

I suggest you try again with a minimal one-liner external command and a minimal one-liner add-in manifest.

Follow these steps: Revit developers guide add-in registration.

Ensure that Revit has read access to its AddIns folder.

Look at the Hello world walkthrough.

Do not say you exhausted all resources. That would take too long and probably exceed your life span. New resources are being added faster than you can consume them, so any attempt is doomed to fail.

The error message is telling you that the problem is not in the internal implementation code, but just in the basic registration.

Why do you add internal to the IExternalApplication implementation? Isn't that a contradiction? What does that mean?

Why do you use The Building Coder VendorId? That is incorrect. You are not The Building Coder.

Your Assembly path is complex and littered with spaces. In general, I try to avoid such complex paths and all spaces in folder names. I also prefer forward slashes to backward ones. You can omit the folder name entirely if you place the DLL in the same place as the add-in manifest in the AddIns folder.

Upvotes: 2

Related Questions