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开发者_如何学C 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.
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.
The fundamental problem here is that .NET doesn't support dynamic assembly unloading. You could reload the assembly, but you would never be able to recover the memory used by the old one
精彩评论