我有一个 WCF 服务库和一个 Windows 服务作为主机。 我想让 ServiceHost 从任何目录而不只是从当前目录加载 WCF 服务库(从该程序集获取服务类型)。
最佳答案
一种方法是配置 -
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MyAssembly2" culture="neutral" publicKeyToken="307041694a995978"/>
<codeBase version="1.0.1524.23149" href="FILE://C:/Myassemblies/MyAssembly2.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
另一种方式是代码—— 程序集 assembly = Assembly.LoadFile(path);
关于c# - 如何告诉 ServiceHost 从任何目录加载程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6490789/