Get location of Assembly DLL in Revit 2025 / .net 8

Get location of Assembly DLL in Revit 2025 / .net 8

stj4M66M
Explorer Explorer
480 Views
6 Replies
Message 1 of 7

Get location of Assembly DLL in Revit 2025 / .net 8

stj4M66M
Explorer
Explorer

Hi

 

I would like to get the location of the DLL file, because I need to read another file placed in the same folder.

In .net framework 4.8 I've used Assembly.GetExecutingAssembly().Location, but it return an empty string in .net 8.

 

I also tried AppDomain.CurrentDomain.BaseDirectory but it returns the directory of Revit.exe.

 

Any suggestions?

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

jeremy_tammik
Alumni
Alumni
Accepted solution
0 Likes
Message 3 of 7

Speed_CAD
Collaborator
Collaborator
Accepted solution

Hi stj4M66M,

 

CodeBase may be deprecated in future versions of .NET, but it still works on .NET 8, try this:

 

string location = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath;

 

Mauricio Jorquera
0 Likes
Message 4 of 7

stj4M66M
Explorer
Explorer

Thanks.

System.Reflection.Assembly.GetExecutingAssembly().CodeBase

Is working.
I already tried that earlier, but it returned "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.7\System.Private.CoreLib.dll". Now I learned, that it was because I ran the plugin from the Add-in Manager. I didn't know that it executes the code in another way.

When I run the code via Add-in/ribbon button I am able to get the assembly location.

 

Thank you for your help.

Regards Steffen

0 Likes
Message 5 of 7

esatis
Advocate
Advocate

I have same problem. Any idea how to get assembly location when running from Add-in Manager?

0 Likes
Message 6 of 7

ricaun
Advisor
Advisor

Add-in Manager probably is loading the your dll file in the memory using something like this:

byte[] assemblyBytes = File.ReadAllBytes("YourAssembly.dll");
Assembly loadedAssembly = Assembly.Load(assemblyBytes);

This make the assembly in the memory instead of a physical file, and make the location empty and the physical file does not lock in the process.

 

That how it works. 🤘

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 7 of 7

stj4M66M
Explorer
Explorer

I havn't found a solution. I ended up creating a ribbon-button.

0 Likes