Silverlight EnterpriseLibraryContainer.Current.GetInstance Activation Error

Topics: Caching Application Block , Silverlight Integration Pack
Jun 29, 2011 at 9:51 AM

 I tried to Implement Silverlight caching in a simple application as shown on the code below: 

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            EnterpriseLibraryContainer.ConfigureAsync(new Uri("Configuration.xaml", UriKind.Relative));
            EnterpriseLibraryContainer.EnterpriseLibraryConfigurationCompleted += new EventHandler<EnterpriseLibraryConfigurationCompletedEventArgs>(EnterpriseLibraryContainer_EnterpriseLibraryConfigurationCompleted);

            this.RootVisual = new MainPage();
            RetrieveCurrentUserRole();
        }

        public void EnterpriseLibraryContainer_EnterpriseLibraryConfigurationCompleted(object sender, EnterpriseLibraryConfigurationCompletedEventArgs e)
        {
            if (e.ConfiguredSuccessfully)
            {
                List<string> systemUsers = new List<string>();
                systemUsers.Add("new1");
                systemUsers.Add("new2");
                
                IServiceLocator locator = EnterpriseLibraryContainer.Current;
                ObjectCache systemUserCache = locator.GetInstance(typeof(ObjectCache), "InMemoryCache") as ObjectCache; //Fails Here

                var notExpiringPolicy = new CacheItemPolicy();
                systemUserCache.Set("InMemoryCache", systemUsers[0], notExpiringPolicy);
            }
        }

But I have received this error:

{Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type ObjectCache, key "InMemoryCache" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Caching.Runtime.Caching.ObjectCache", name = "InMemoryCache".
Exception occurred while: Calling constructor Microsoft.Practices.EnterpriseLibrary.Caching.InMemoryCache(System.String name, System.Int32 maxItemsBeforeScavenging, System.Int32 itemsLeftAfterScavenging, System.TimeSpan expirationPollingInterval).
Exception is: ArgumentOutOfRangeException - Specified argument was out of the range of valid values.
Parameter name: pollInterval
-----------------------------------------------
At the time of the exception, the container was:

  Resolving Microsoft.Practices.EnterpriseLibrary.Caching.InMemoryCache,InMemoryCache (mapped from Microsoft.Practices.EnterpriseLibrary.Caching.Runtime.Caching.ObjectCache, InMemoryCache)
  Calling constructor Microsoft.Practices.EnterpriseLibrary.Caching.InMemoryCache(System.String name, System.Int32 maxItemsBeforeScavenging, System.Int32 itemsLeftAfterScavenging, System.TimeSpan expirationPollingInterval)
 ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: pollInterval
   at Microsoft.Practices.EnterpriseLibrary.Common.Utility.RecurringWorkScheduler..ctor(TimeSpan pollInterval)
   at Microsoft.Practices.EnterpriseLibrary.Caching.InMemoryCache..ctor(String name, Int32 maxItemsBeforeScavenging, Int32 itemsLeftAfterScavenging, TimeSpan expirationPollingInterval)
   at BuildUp_Microsoft.Practices.EnterpriseLibrary.Caching.InMemoryCache(IBuilderContext )
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
   --- End of inner exception stack trace ---
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides)
   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
   at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)
   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
   --- End of inner exception stack trace ---
   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)}

 

It seems that the error is throwing on the Microsoft.Practices.ServiceLocation.dll

 

Here is also the configuration file (Configuration.xaml)

<?xml version="1.0" encoding="utf-8"?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:el="http://schemas.microsoft.com/practices/2011/entlib">
    <el:CachingSettings DefaultCache="InMemoryCache" x:Key="cachingSilverlightConfiguration">
    <el:CachingSettings.Caches>
      <el:InMemoryCacheData MaxItemsBeforeScavenging="500" ExpirationPollingInterval="00:00:00" Name="InMemoryCache" />
      <el:IsolatedStorageCacheData ExpirationPollingInterval="00:00:00" Name="IsolatedStorageCache" />
    </el:CachingSettings.Caches>
  </el:CachingSettings>
</ResourceDictionary>
Jun 30, 2011 at 5:50 AM

Hi Gildon,

Can you try adding a value to the ExpirationPollingInterval? It seems that it considered "00:00:00" as an invalid value.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com