gpt4 book ai didi

c# - 在子目录中运行时加载私有(private)程序集

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:23 25 4
gpt4 key购买 nike

我一直在尝试加载位于应用程序基目录下子目录中的私有(private)程序集。我有一个名为 Sparrow.dll 的程序集,它位于插件目录下(也在应用程序基础目录下)。每当我调用 Assembly.Load("Sparrow") 时,我都会收到 System.IO.FileNotFoundException。

我将 app.exe.config 与标签一起使用,它与具有以下行的同一程序集的强命名版本一起工作;

Assembly assem = Assembly.Load("Sparrow");

但是,当我将程序集更改为弱程序集时,它不起作用。

配置文件内容如下;

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly name="Sparrow, Culture=neutral, PublicKeyToken=xxxxxx">
<codeBase version="1.0.1.1" href="plugins/Sparrow.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

我读了很多东西,但我不确定使用标记来定位弱程序集是否是一种好的做法。

最佳答案

您可以使用 probing为此目的的元素:

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="plugins" />
</assemblyBinding>
</runtime>
</configuration>

该元素表示将在 plugins 子文件夹中搜索程序集。但是请注意,只能以这种方式指定应用程序目录的后代路径上的目录。

你问题中的配置文件有错误。根据文档,XML 配置应如下所示:

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Sparrow"
publicKeyToken="null"
culture="neutral" />
<codeBase version="1.0.1.1" href="plugins/Sparrow.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

但是,我认为在您的情况下使用 probing 元素会是更好的选择。

关于c# - 在子目录中运行时加载私有(private)程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26530731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com