Get location of DLL from C# code.

Get location of DLL from C# code.

Anonymous
Not applicable
13,488 Views
6 Replies
Message 1 of 7

Get location of DLL from C# code.

Anonymous
Not applicable

I need to retrieve the directory where the plugin DLL resides. When I use the usual C# code for this, Directory.GetCurrentDirectory(), I get the location of the RevIt installation on my machine, and not the directory where the running DLL is located. Is there a way, through the API, to retrieve the location of the running DLL?

 

Thanks in advance,

 

Scott S

Research Programmer

Center for Research Computing

University of Notre Dame

0 Likes
Accepted solutions (1)
13,489 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Accepted solution

String executablePath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

 

should do the trick.

 

Message 3 of 7

Anonymous
Not applicable

Absolutely, that did it! Thanks so much!

0 Likes
Message 4 of 7

jaboone
Advocate
Advocate

I am using macro and getting an error on assembly not found.  Is there a solution for that?

 

The name 'Assembly' does not exist in the current context (CS0103) - C:\ProgramData\Autodesk\Revit\Macros\2015\Revit\AppHookup\CConvert\Source\CConvert\ThisApplication.cs:55,62

Learning as I go
0 Likes
Message 5 of 7

Dale.Bartlett
Collaborator
Collaborator
I'm guessing that macros (as opposed to addins) are code run within the document. As such there is no dll or assembly.



______________
Yes, I'm Satoshi.
0 Likes
Message 6 of 7

jaboone
Advocate
Advocate

I am using application specific macro so I can use VS later.  This is only short term testing right now.  There are dll.

Learning as I go
0 Likes
Message 7 of 7

Dale.Bartlett
Collaborator
Collaborator

The solution accepted here does not work for 2017. It returns the location of the .addin file, not the location of the executing dll which is in a .bundle sub-folder. I have only just picked up that my support help files are not being found, although were previously. Has there been a change for 2017? I have also tried various suggestions with no success. In fact they return the same.

public static string GetDLLFolder()
        {
            string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            return Path.GetDirectoryName(path);
        }

Thanks, Dale




______________
Yes, I'm Satoshi.
0 Likes