使用 MEF 和 WCF 时重写 dll 文件
在我当前的项目中,我使用 WCF 服务向客户端发送 dll 文件。 dll 文件包含客户端用来可视化数据的 UserControl。 然而,有时服务会引入新的用户控件,而客户端对此并不知情。发生这种情况时,我将新的 dll 文件发送给客户端,以便他们拥有最新版本的 UserControls。
然而,当我想在客户端 HD 上写入这个新的 dll 文件(使用 FileStream)时,我得到一个异常,说该文件被另一个进程使用(当然,客户端总是在其上有一个 UserControl 的汇编版本)高清,所以必须覆盖)。
有什么方法可以覆盖这个文件而不出现错误吗?我正在使用 MEF 读取客户端项目中的程序集文件。要将程序集文件发送给客户端,我只需将文件名作为字符串发送,并将文件内容发送到字节数组中。
On my current project, I'm sending dll files to clients using a WCF service.
The dll files contain UserControls which the clients use to visualize data.
However, sometimes new UserControls are introduced by the service, without the clients knowing about this. When this happend, I send the new dll file to the clients so they have the latest version of the UserControls.
However, when I want to write this new dll file on the clients HD (using a FileStream), I get an exception saying that the file is used by another process (of course, the clients always have an assembly version of the UserControls on their HD, so this has to be overwriten).
Is there any way to overwrite this file without getting an error? I'm using MEF to read the assembly files in the client project. To send the assembly file to the clients, I just send the filename as a string and the file's content in a byte array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这通常是通过影子复制完成的,但我找不到任何东西确定它是否适用于 MEF。
如果您的新控件可以在关闭并重新打开应用程序时加载,那么您可以在使用 MEF 编写之前复制所有插件。
这是一篇博客文章,有人基本上在尝试MEF + Shodow Copy,以及特别相关的评论。
This is usually done with Shadow Copying, but I can't find anything definitive as to whether it works with MEF.
If its acceptable for your new control to be loaded on closing and re-opening the application, then you can copy all your plugins prior to composing with MEF.
Here is a blog post with somebody essentially trying MEF + Shodow Copy, and a particularly relevant comment.