In a .NET Compact Framework 3.5 application I'm doing a version check in a fairly tight loop in order to know whether or not another assembly needs to be "upgraded" (have a new copy in another directory copied over it, then start it up again).
The problem is that Assembly.LoadFrom(path).GetName().Version
locks the file and prevents said copying over.
AssemblyName.GetAssemblyName(path)
would be a better way to get this (thanks to this SO answer), as it doesn't permanently load the assembly into the AppDomain and thus doesn't lock the file, but it isn't available in the Compact Framework.
I could create a new AppDomain
, but can't use the new domain's Load
method as that's not supported in the Compact Framework.
As a last resort I thought I'd allow the assembly to actually be loaded with the Assembly.Load(byte[])
overload, which would cause a massive memory "leak" in a tight loop since they're never unloaded. To counter that I intended to first hash the assembly's byte array and check a cache of versions for a previous hit. However, you guessed it, the byte array overload for Assembly.Load()
isn't supported in the Compact Framework.
I also considered adding AssemblyFileVersions, since they're easier to check anyway, but that's another thing in the growing heap of things not supported in the Compact Framework (my thanks to this SO answer for not having to try this).
Please, tell me what I'm trying to do is possible so I stop hating this framework so much?