开发者

Set assembly reference path

I built an application in C# with this structure:

SystemPath

-- MainApplication.EXE

-- API.dll

-- Modules

------- Module1.dll

------- Module2.dll

The MainApplication.exe has a referency to the assembly API.dll. And it uses the assemblies Module1 and Module2 by "Assembly.Load(dllFile)". The files Module1.dll and Module2.dll also needs the file API.dll.

So, they need the API.dll in same开发者_开发知识库 path they are and i need to put the file API.dll in both directories (SystemPath and Modules).

What i want is a way to tell the modules that the file API.dll is in that folder, when i'm loading it with the Assembly.Load.

I can't use the Global Assembly Cache and can't change this structure.

What can i do to solve this?


In your MainApplication.exe.config file, you can add a <probing> element that specifies a semicolon-delimited list of subdirectories that will be searched when an assembly is loaded. For example:

<?xml version="1.0"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="Modules" />
        </assemblyBinding>
    </runtime>
</configuration>

With this in your configuration, you'll be able to do an Assembly.Load or reference on Module1; and since your application root is still at the top-level, if Module1 does an Assembly.Load or reference to API.dll, it will get it from the top-level directory automatically.


Are you sure that API.dll needs to be in the same folder than Module1/2.dll? API.dll from the main app is already loaded, when you load the Modules programmatically. Just make sure they have been compiled with same version of API.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜