更新:我已经严格按照建议命名我的 DLL,但我的 codeBase 标签似乎没有任何效果。 Fusion 没有将我的自定义目录显示为 dll 扫描目标之一。启动我的服务仍然会抛出 FileNotFoundException。
我的项目根目录的子文件夹中有几个 exe。我需要将一个 DLL 放入根目录并启用所有这些 exe 来引用它。到目前为止,我已经编辑了我的 exe 的 app.config 文件:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="resources"
publicKeyToken="fe437a7f5a917214"
culture="neutral" />
<codeBase version="1.0.0.0"
href="file:///c:/program files (x86)/root Directory/resources.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我的 exe 有一个通过 IDE 设置的引用,“复制本地”选项设置为 false。然而,当我尝试启动我的 exe(它是一个 Windows 服务)时,它会出错并写入 Windows 事件日志并抛出 System.IO.FileNotFoundException。
我错过了什么?
最佳答案
href="file:///c:/program files (x86)/root Directory/resources.dll"/>
需要
href="file:///c:\program files (x86)\root Directory\resources.dll"/>
关于c# - 在运行时引用外部 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8329699/