How to get the location of the DLL currently executing?

后端 未结 5 1539
情话喂你
情话喂你 2020-11-29 04:38

I have a config file that I need to load as part of the execution of a dll I am writing.

The problem I am having is that the place I put the dll and config file is n

5条回答
  •  Happy的楠姐
    2020-11-29 05:05

    Reflection is your friend, as has been pointed out. But you need to use the correct method;

    Assembly.GetEntryAssembly()     //gives you the entrypoint assembly for the process.
    Assembly.GetCallingAssembly()   // gives you the assembly from which the current method was called.
    Assembly.GetExecutingAssembly() // gives you the assembly in which the currently executing code is defined
    Assembly.GetAssembly( Type t )  // gives you the assembly in which the specified type is defined.
    

提交回复
热议问题