Error in Windows Service when I update a signed dll

1

I have a Windows service that the executable calls a dll (which I'll call MyMyDll.dll) with version 0.6.7.3, for example.

Everything works correctly until I updated that dll to version 0.6.7.4. That when restarting the service, so that it takes the new version of the dll, it returns the following error:

  

The service can not be started. System.IO.FileLoadException: I do not know   You can load the file or assembly 'MyDiName, Version = 0.6.7.3,   Culture = neutral, PublicKeyToken = 59f75f9107acaf71 'not one of your   dependencies. The assembly manifest definition does not match   with the reference to the assembly. (Exception from HRESULT: 0x80131040)   File name: 'NombreMiDll, Version = 0.6.7.3, Culture = neutral,   PublicKeyToken = 59f75f9107acaf71 'in   CallerCofnaService.Service1.OnStart (String [] args) in   System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback (Object   state)

     

AVS: The assembly link record is deactivated. For   enable the error log of the assembly link, set   the registry value [HKLM \ Software \ Microsoft \ Fusion! EnableLog]   (DWORD) as 1. Note: there is a decrease in the associated performance   error log of the assembly link. To deactivate this   feature, delete the registry value   [HKLM \ Software \ Microsoft \ Fusion! EnableLog].

Would anyone know how to avoid this error, and be able to update the dll without any problem? The dll is updated automatically and alone, verifying every X time if there is a new version. If there is the download and restart the service.

The dll I have compiled myself, and it is written in c # Framework 2.0 (project requirements).

Thanks in advance.

    
asked by marsim86 10.01.2018 в 11:19
source

4 answers

0

First, thank you very much for your collaboration. The problem (and the subsequent solution) I found in keeping the value fixed AssemblyVersion and modify only the AssemblyFileVersion.

This way, even if the dll is signed, when calling it use the AssemblyVersion, but the update system uses the AssemblyFileVersion.

Thank you very much to the whole forum, and thank you very much for the answers. Using assemblyBinding as suggested Sergio Parra has given me ideas to optimize the compilation process.

    
answered by 16.01.2018 / 13:19
source
0

You have to compile all the service and publish it on the machine again. The service you have awaits the dll NombreMiDll.dll with the version 0.6.7.3 but you are passing the version 0.6.7.4 so you can not find the dll with which it was compiled initially.

    
answered by 10.01.2018 в 13:32
0

Try this, although I have read that it is not recommended to change the DLL at run time:

try
        {
            DirectoryInfo info = new DirectoryInfo(Environment.SpecialFolder.MyDocuments.ToString());
            var dlls = info.GetFiles(@"*.dll").ToList();
            foreach (FileInfo item in dlls)
            {
                var loadedDll = Assembly.LoadFile(item.FullName);
            }
        }
        catch (Exception)
        {
            throw;
        }

Response obtained from: link

    
answered by 10.01.2018 в 13:51
0

You can configure the assemblyBinding element in your configuration file to be able to use one version or another of an assembly by applying bindingRedirect . An example can be

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <bindingRedirect oldVersion="1.0.0.0"
                             newVersion="2.0.0.0"/>
            <codeBase version="2.0.0.0"
                      href="http://www.litwareinc.com/myAssembly.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>
    
answered by 10.01.2018 в 13:55