2

In my Windows Service project, I have refereed Enterprise Library Caching 5.0.505, but I get the following error on service start

Service cannot be started. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    File name: 'Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

App.Config

<configSections>

    <section name="cachingConfiguration" 
             type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
             requirePermission="true" />
  </configSections>


<cachingConfiguration defaultCacheManager="Cache Manager">
    <cacheManagers>
      <add name="Cache Manager" 
           type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
           expirationPollFrequencyInSeconds="60" 
           maximumElementsInCacheBeforeScavenging="50000" 
           numberToRemoveWhenScavenging="1000" 
           backingStoreName="NullBackingStore" />
    </cacheManagers>
    <backingStores>
      <add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
           name="NullBackingStore" />
    </backingStores>
  </cachingConfiguration>

1 Answer 1

4

This occurs when the referenced assembly doesn't match with the one in the bin folder.

Try adding this to your .config file:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Caching" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.505.0" newVersion="5.0.505.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Sign up to request clarification or add additional context in comments.

4 Comments

But how can that be, I have refereed throw nugget, I double checked the properties of those refereed dlls
Are you working with multiple projects? If so, you need to check if all the projects are referencing the same version.
Yes, there is a dependent project which is using "5.0.414.0", but since this service project is using latest version, i thought this would take the precedence?
If in your project references, the assembly is marked with "Specific Version" = true, no precedence will be taken. This is valid to the dependent project too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.