TypeLoadException for Hello Ribbon

TypeLoadException for Hello Ribbon

lionel.kai
Advisor Advisor
1,424 Views
7 Replies
Message 1 of 8

TypeLoadException for Hello Ribbon

lionel.kai
Advisor
Advisor

I've been searching for a basic "Hello Ribbon" tutorial that creates a simple button on a new Ribbon tab, but haven't yet found one. I was recently pointed to:

https://thebuildingcoder.typepad.com/files/revit_2014_api_developer_guide.pdf

which has a decently basic one on page 18. It did require a separate "Hello World", but that was easy enough. My problem with this one is the attached error when it tries to load in Revit. This page:

https://adndevblog.typepad.com/aec/2013/03/systemtypeloadexception-with-revit-add-in.html

seems to indicate it's something related to actually finding the dll, the namespace, and/or the .NET version. I've tried various things, and am using 4.6 (for Revit 2018) as far as I can tell, but still get the error. I've attached my VisualStudio solutions.

 

In the larger scheme of things I'd like to have a self-contained example (that produces ONE .dll to deploy), so that I can scale it up later, but at this point I'd settle for getting anything to work properly (other examples I've tried recently or over the years have resulted in a panel but no button, or other weirdness).

TypeLoadException.png


Lionel J. Camara
BIM Manager at KAI Hawaii, Inc. - Structural and Forensic Engineers
Autodesk Certified Professional
0 Likes
Accepted solutions (3)
1,425 Views
7 Replies
Replies (7)
Message 2 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @lionel.kai ,

Try using this below link

https://forums.autodesk.com/t5/revit-api-forum/revit-cannot-run-external-application/td-p/8192140 

 

If this doesn't help could you please show us your .addin manifest file?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

lionel.kai
Advisor
Advisor

I think my .addin file looks ok (was in the solution .zip, but I've attached it again as well - had to put it in a .zip to upload anyway).

 

The thread you linked to also mentioned an issue with referencing a .dll (though the Building Coder link doesn't seem to have anything to do with that), so I put the Hello World code in the AddPanel .cs file so that it would be in one .dll (which is what I originally wanted anyway), but I'm not sure if I need separate entries in the .addin file for each command being referenced by a button? And I'd probably want to add buttons that trigger commands in other people's .dll's, so I'd want it to work either way, but in any case I got the same result (the modified .cs is also in the new .zip). 😞


Lionel J. Camara
BIM Manager at KAI Hawaii, Inc. - Structural and Forensic Engineers
Autodesk Certified Professional
0 Likes
Message 4 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @lionel.kai .

Your code works fine and also I think I figured out what is causing the problem in your project!😀

In your addin file, the Full class name is wrong

You used "P" instead of "p"

So change

<FullClassName>AddPanel.CsAddPanel</FullClassName>

to

<FullClassName>AddPanel.CsAddpanel</FullClassName>


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 8

lionel.kai
Advisor
Advisor

AHHHH! It figures it was something dumb like that... 🙂

 

I renamed the Class instead (to "P"), and that fixed the above error, but now I get a different one (below). A panel appears on the Add-Ins tab, but no button...ArgumentException.png


Lionel J. Camara
BIM Manager at KAI Hawaii, Inc. - Structural and Forensic Engineers
Autodesk Certified Professional
0 Likes
Message 6 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @lionel.kai ,

In your code

new PushButtonData("HelloWorld", "HelloWorld", @"AddPanel.dll", "AddPanel.CsHelloWorld")

add the full path of your AddPanel.dll file.

For example

new PushButtonData("HelloWorld", "HelloWorld", @"C:\Users\MyRevitPlugin\AddPanel\AddPanel.dll", "AddPanel.CsHelloWorld")

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 8

mhannonQ65N2
Collaborator
Collaborator
Accepted solution

Instead of hardcoding the path, I strongly recommend that you use 

System.Reflection.Assembly.GetExecutingAssembly().Location

to get the path of the currently running dll (i.e. your plugin).

0 Likes
Message 8 of 8

lionel.kai
Advisor
Advisor

Woo-hoo!

@naveen.kumar.t After fixing that path, I got a similar error for the Uri - but that was just as easily fixed by putting the full path there as well. 🙂

@mhannonQ65N2 Thanks for the tip! I found something similar in one of the other "simple" tutorials that I couldn't get to run, so I modified it to something a little more useful for the icon:

var iconPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
Uri uriImage = new Uri(System.IO.Path.Combine(iconPath, "LACMA DOORS.png"));

Along the way, I even figured out what the @ was for, LOL! Now I just need to figure out how to put it on a new tab. 🙂


Lionel J. Camara
BIM Manager at KAI Hawaii, Inc. - Structural and Forensic Engineers
Autodesk Certified Professional
0 Likes