gpt4 book ai didi

c# - 远程代码库

转载 作者:太空宇宙 更新时间:2023-11-03 14:36:28 24 4
gpt4 key购买 nike

我有一个dll。该 dll 已上传到服务器上。我希望每次应用程序开始从服务器获取“最新的”dll,所以我在我的 app.config 中使用了以下代码。为什么它不起作用?

这是 app.config 文件:

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ReflectionTest"
publicKeyToken="f94c9b9f0707ee96"
culture="neutral" />
<codeBase version="1.0.0.0"
href="http://127.0.0.1/ReflectionTest.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

最佳答案

首先,你可能走错了路。即使您没有更改版本,您的应用程序也可能最终使用程序集的旧副本。

假设您的 <codebase> 中有一个有效的 URI元素,当您的应用程序首次运行时,运行时将不会在其中找到程序集,直到它探测您的代码库。然后,它将程序集下载到 GAC。当您的应用程序再次运行时,运行时将在 GAC 中找到该程序集,因此它不需要探测它。

而不是使用 <codebase> ,考虑使用反射。具体来说,您可能想使用 Assembly.LoadFrom(assemblyUri)在您的应用程序中,从应用程序设置中获取 URI。从那里,您将使用 Reflection API 创建对象,特别是使用 Activator.CreateInstance<T>() .

至于从您的服务器获取程序集,请确保您的 DLL 位于正确的位置,并且您的 Web 服务器正在运行并正确配置。

关于c# - 远程代码库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/812493/

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