Share via


Using Enterprise Transient fault handling block with Azure Cache

 I mentioned in an earlier blog about the importance of having a retry mechanism in applications that use Azure Cache. An easy way to do this is by using the enterprise transient fault handling block.

I've noticed that an application using the Windows Azure SDK 1.8 (October 2012 release) and Transient Fault handling block (version 5.1.1209.0) can fail to start with the callstack below:

 System.Reflection.TargetInvocationException occurred
 HResult=-2146232828
 Message=Exception has been thrown by the target of an invocation.
 Source=mscorlib
 StackTrace:
 at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
 at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
 at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
 at System.Activator.CreateInstance[T]()
 at Microsoft.Practices.TransientFaultHandling.RetryPolicy`1..ctor(RetryStrategy retryStrategy)
 at WebRole1._Default.Page_Load(Object sender, EventArgs e) in c:\Projects\WindowsAzure1\WebRole1\Default.aspx.cs:line 23
 InnerException: System.IO.FileLoadException
 HResult=-2146234304
 Message=Could not load file or assembly 'Microsoft.ApplicationServer.Caching.Core, Version=101.0.0.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)
 Source=mscorlib
 FileName=Microsoft.ApplicationServer.Caching.Core, Version=101.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 FusionLog==== Pre-bind state information ===

 

Here is a simple workaround to get past this issue - In your application config (app.config or web.config), add the following assembly redirection snippet:

 

 <configuration>
 <runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 <dependentAssembly>
 <assemblyIdentity name="Microsoft.ApplicationServer.Caching.Core"
 publicKeyToken="31bf3856ad364e35"
 culture="neutral" />
 <!-- Assembly versions can be redirected in application, 
 publisher policy, or machine configuration files. -->
 <bindingRedirect oldVersion="101.0.0.0" newVersion="1.0.0.0" />
 </dependentAssembly>
 </assemblyBinding>
 </runtime>
 </configuration>