| Reply To Message: |
| Posted By |
Don on 4/7/2005 7:47:49 AM |
| Subject: |
Get assembly version - locked forever |
| Message: |
Recently, I downloaded some CF sample code that compares the version number of a program running on a mobile device with a version number returned from a web service. If they didn't match, a new version of the program was downloaded cab file and shellexec'd to install it. For some unknown reason, the programmer decided that the program that does the comparing and updating should close immediately after shellexec. Now I think I see why: The program loads the assembly to get the version number like so: ... Assembly a = null; AssemblyName assname = new AssemblyName(); // If assembly does not exists, presume the version to be 0.0.0 assname.Version = new Version('0.0.0'); // Try obtaining assembly version try { if ( File.Exists(aProgramPath) ) { a = Assembly.LoadFrom(aProgramPath); assname = a.GetName(); } } catch(Exception) { } // Release assembly, so that its file is not locked anymore a = null; ... The last part simply doesn't work. The assembly remains locked until the program that called it is closed. This means that after checking the version number, you can't install it because you've got it locked. There is apparently no way to release the lock in CF. In the 'regular' framework, you would load the assembly into an AppDomain and the locked assembly will be released when the AppDomain is destroyed. But the CF doesn't support AppDomain. Another option is to first copy the assembly and get the version from that. That's an option if you have the space on the device to hold two copies of your programs. That's necessary because you can't delete the copies because they're locked. There are ways around this but they are hacks. One way would be to have a separate program that checks version numbers that is called from the main update program. You can pass it the name of the assembly and it can output its results to a file or something. |
|