我已经查看了其他几篇关于如何让 CLR 查找不在同一文件夹或可执行文件的任何子文件夹中的程序集的帖子,但我无法让它为我工作。 ClassLibrary1.dll 是一个未签名的程序集。示例显示:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ClassLibrary1"/>
<codeBase version="1.0.0.0"
href=file:///C:\somepath\subfolder\ClassLibrary1.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我创建了一个控制台应用程序,并将上面的内容和正确的路径放在它的配置文件中,但仍然收到一条消息,指出它找不到 ClassLibrary1.dll。我使用了 FUSLOGVW,它甚至没有检查 CodeBase 元素中提供的文件夹。有谁知道为什么这不起作用?
最佳答案
来自 MSDN :
If the assembly has a strong name, the codebase setting can be anywhere on the local intranet or the Internet. If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.
这意味着如果您不对程序集进行签名,那么它必须位于应用程序文件夹或应用程序文件夹的子文件夹中。如果您想将应用程序放在 c:\Program Files\MyApplication 中,而将程序集放在 c:\MyAssemblies 中,则必须对程序集进行签名。
关于.Net 代码库元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9688269/