远程代码库
我有一个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>
I have a dll. That dll is uploaded on a server. I want that each time the application starts to get the "latest" dll from the server, so I've used the following code in my app.config. Why isn't it working?
here is the app.config file:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,你可能走错了路。 即使您没有更改版本,您的应用程序最终也可能会使用程序集的旧副本。
假设
元素中存在有效的 URI,当您的应用程序首次运行时,运行时在探测您的代码库之前不会找到该程序集。 然后,它会将程序集下载到 GAC。 当您的应用程序再次运行时,运行时将在 GAC 中找到该程序集,因此不需要探测它。考虑使用反射,而不是使用()。
。 具体来说,您可能希望在应用程序中使用Assembly.LoadFrom(assembleUri)
,从应用程序设置中获取 URI。 从那里,您可以使用 Reflection API 创建对象,特别是使用 Activator.CreateInstance至于从服务器获取该程序集,请确保 DLL 位于正确的位置,并且 Web 服务器正在运行且配置正确。
First, you may be on the wrong track. Even if you didn't change the version, your application may end up using an older copy of the assembly.
Assuming a valid URI in your
<codebase>
element, when your application runs for the first time, the runtime will not find the assembly in until it probes your codebase. Then, it will download the assembly to the GAC. When your application runs again, the runtime will find that assembly in the GAC, so it will not need to probe for it.Instead of using
<codebase>
, consider using Reflection. Specifically, you might want to useAssembly.LoadFrom(assemblyUri)
in your application, getting the URI from an application setting. From there, you'd create objects using the Reflection API, particularly usingActivator.CreateInstance<T>()
.As for getting that assembly from your server is concerned, make sure that your DLL is in the right location and that your web server is running and properly configured.
您的 .dll 实际上在该位置可用吗? 您是否通过某些网络应用程序提供服务?
如果您将该 URL 键入网络浏览器,它是否允许您下载或打开该文件?
Is your .dll actually available at that location? Are you serving it up through some web application?
If you type that URL into a web browser, does it let you download or open that file?