Search code examples
c#.net-assembly

Set manully assembly reference


i have this structure

--Loader.exe
--Core.dll
--Plugins/Test.dll

--C:\Program Files\Program\Program.exe

Assembly Test.dll has reference to Core.dll which is fine. When i run Loader.exe it inject Core.dll into another process (Program.exe) and when it does it's trying to load assembly Test.dll. The problem is that Test.dll is looking for reference Core.dll in path C:\Program Files\Program\ instad of path where it was loaded.

Solution: (i'm searching)

I'm simly looking for way how to load reference from execute path instand of another's process path.

Question:

Don't understand if Core.dll loads Assembly which has reference to Core.dll why it can't load from itself ?


Solution

  • The directory from which referenced assemblies are loaded is determined by the configuration of the AppDomain in which your code is running in, specifically, by the AppDomain.BaseDirectory and AppDomain.RelativeSearchPath properties. By default, the assemblies are loaded from the directory which contains your entry point assembly (usually your main EXE application assembly). To customize these paths you need to create a custom AppDomain. Alternatively, you can load the assemblies manually, using Assembly.LoadFile or Assembly.LoadFrom for example.