C#: How do I get the path of the assembly the code is in?
        Posted  
        
            by George Mauer
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by George Mauer
        
        
        
        Published on 2008-09-09T20:12:28Z
        Indexed on 
            2010/05/22
            9:20 UTC
        
        
        Read the original article
        Hit count: 448
        
Is there a way to get the path for the assembly in which the current code resides? I do not want the path of the calling assembly, just the one containing the code.
Basically my unit test needs to read some xml test files which are located relative to the dll. I want the path to always resolve correctly regardless of whether the testing dll is run from TestDriven.NET, the MbUnit GUI or something else.
Edit: People seem to be misunderstanding what I'm asking.
My test library is located in say c:\projects\myapplication\daotests\bin\Debug\daotests.dll and I would like to get the "*c:\projects\myapplication\daotests\bin\Debug*" path.
The three suggestions so far fail me when I run from the MbUnit Gui:
Console.Out.Write(Environment.CurrentDirectory) gives c:\Program Files\MbUnit
Console.Out.Write(System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location) gives C:\Documents and Settings\george\Local Settings\Temp\ ....\DaoTests.dll
Console.Out.Write(System.Reflection.Assembly.GetExecutingAssembly().Location) gives the same as the previous
© Stack Overflow or respective owner