2

we have an application that looks at a shared folder for a newer version of the application.

We came up with the following code to check whether the assemblies versions are different (the running at client, and the one at server shared folder)

            //Obtains the current version of the Entry Assembly
            versaoAtual = Assembly.GetEntryAssembly().GetName().Version;

            //Path for the the new Assembly at a shared folder at server
            string arquivoServidor = Path.Combine(maquinaCliente.DiretorioDeploy, @"SAMEDigital.Client.exe");

            //If the file does not exist, the version is the same, so it would not be updated
            if (!File.Exists(arquivoServidor))
            {
                versaoNova = versaoAtual;
            }
            else
            {
                //Creates a temporary AppDomain for loading the server assembly
                AppDomain ad = AppDomain.CreateDomain("TempAppDomainSAMEDigitalClient");

                //Obtains the server version of the server assembly
                versaoNova = ad.Load(File.ReadAllBytes(arquivoServidor)).GetName().Version;

                //Unload the the temporary AppDomain 
                AppDomain.Unload(ad);
            }

But the results are not the expected, both variables display the same version (the version that is actually running). Shouldn´t this work? As we are getting the version of the running assembly and then loading another assembly and acquiring the version of this one.

Could someone, please, clarify what we are doing wrong?

Thanks in advance.

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
Leandro Tavares
  • 400
  • 1
  • 3
  • 18
  • 1
    The MSDN article for AppDomain.Load(byte[]) specifically warns about this: "This method should be used only to load an assembly into the current application domain" – Hans Passant Feb 17 '14 at 20:26
  • 1
    Thanks! Hans :) I jumped over this remark at MSDN. Even so, I though the version would be relative to the assembly, not mattering the AppDomain. I was wrong. Now I need to come up with a solution to check the assembly version. I tried the basic Assembly.Load method, but with this I am not able to unload the assembly. – Leandro Tavares Feb 17 '14 at 20:35
  • 2
    Try checking out this question: http://stackoverflow.com/questions/187999/how-do-i-get-the-version-of-an-assembly-without-loading-it – Eyal H Feb 17 '14 at 20:36
  • 1
    Thanks Eyal! This will solve my problem! – Leandro Tavares Feb 17 '14 at 20:39

0 Answers0