c# - 在运行时引用外部 dll

标签 c# .net

更新:我已经严格按照建议命名我的 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/

相关文章:

.net - 使用 Autofac 在 .NET Framework 中注册 IHttpClientFactory DI

php - .NET Framework 中的 mysql_real_escape_string()

c# - 是否有任何独立的 C#/.NET 调试器?

c# - 在 WinForms 中实现干净的 UI 功能同时保持体面的解耦架构的最佳方法是什么?

c# - VB.NET WithEvents 关键字行为 - VB.NET 编译器限制?

c# - 在 MonoMac 中打开 Cocoa 窗口

c# - 我可以从当前正在执行的函数中按程序获取参数名称/值吗?

c# - 当使用的字体不支持这种语言时,Label 控件如何正确显示日语字符?

c# - Datagridview单元格样式更新

c# - 如何在文件夹中找到第二个最新文件