Why I don't have to copy the RevitAPI.dll and RevitAPIUI.dll files to my add-in .dll file location path

Why I don't have to copy the RevitAPI.dll and RevitAPIUI.dll files to my add-in .dll file location path

Omar_Amen
Advocate Advocate
915 Views
6 Replies
Message 1 of 7

Why I don't have to copy the RevitAPI.dll and RevitAPIUI.dll files to my add-in .dll file location path

Omar_Amen
Advocate
Advocate

Hi there,
my question is why we don't have the RevitAPI.dll and RevitAPIUI.dll to the add-in .dll file path although we need to copy any other external reference dll files to the add-in location path,
what I want to achieve is running my addin successfully with external dll references with no need to copy them to the add-in location folder, but instead I want to refer to them by another location path [not the same path of the add-in location folder path that contains the add-in dll file],
just like what is happening with the RevitAPI.dll and RevitAPIUI.dll.

thanks in advance,

0 Likes
Accepted solutions (2)
916 Views
6 Replies
Replies (6)
Message 2 of 7

jeremy_tammik
Alumni
Alumni
Accepted solution

RevitAPI.dll and all other Revit API .NET assemblies are loaded by Revit.exe itself. They all live in the same AppDomain, together with your add-in, which is also loaded and executed by Revit.exe. So, these references are always present:

  

https://duckduckgo.com/?q=.net+appdomain

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 7

Omar_Amen
Advocate
Advocate

thanks Jeremy,
now I know why this happens for the revitAPI & revitAPIUI,
so can I actually attach a dll reference to the Revit app domain without coping the dll file to the addin installation folder path?
I tried to copy the external dll to the default Revit addins folder "C:\ProgramData\Autodesk\Revit\Addins\2020" but it didn't work, it has to be copied and be attached to my addin in the same folder location

0 Likes
Message 4 of 7

moturi.magati.george
Autodesk
Autodesk

Hi @Omar_Amen 

 

I believe you can reference your dll file with the full path in the .addin file using the <Assembly> tag.

  Moturi George,     Developer Advocacy and Support,  ADN Open
Message 5 of 7

Omar_Amen
Advocate
Advocate

Hi @moturi.magati.george,
thank you for your interest, but what I mean is how to reference external dll to my addin dll file without coping the external dll to my addin dll folder location

0 Likes
Message 6 of 7

Omar_Amen
Advocate
Advocate
Accepted solution

Thanks Jeremy,
I solved it thanks to your clarification 🙏,
I got the current app domain, reference the dll using Assembly.LoadFrom(PATH);
then added the class [type] I need to the current app domain using currentDomain.CreateInstanceFromAndUnwrap(pathToDll, classFullName);
to be as:

AppDomain currentDomain = AppDomain.CurrentDomain;
string pathToDll = @"PATH...";
Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom(pathToDll);
Form myObject = currentDomain.CreateInstanceFromAndUnwrap(pathToDll,"classFullName") as Form;
myObject.ShowDialog();


Reference URL: load a DLL reference from a different folder

0 Likes
Message 7 of 7

jeremy_tammik
Alumni
Alumni

Cool. Congratulations on solving and glad it helped. Another approach is to use an assembly resolver:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open