FileNotFoundException when accessing EnterpriseLibraryContainer in Silverlight

Topics: Caching Application Block , Enterprise Library Core, Silverlight Integration Pack
Oct 20, 2011 at 10:59 AM
Edited Oct 20, 2011 at 11:01 AM

I have a Silverlight Application and would like to use the entlib "Cache Application Block". But when i try to access the Cach with the following lines:

ObjectCache cache = EnterpriseLibraryContainer.Current.GetInstance<ObjectCache>("CacheName");

I get an Exception:

{System.IO.FileNotFoundException: Die Datei oder Assembly System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 oder eine Abhängigkeit davon wurde nicht gefunden. The system cannot find the file specified.File name: 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'   at Microsoft.Practices.EnterpriseLibrary.Common.Utility.XamlActivator.CreateInstance[T](String typeXName)   at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.AddValidationExtension()   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator..ctor(IUnityContainer container)   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource)   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer()   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet()   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current()   at SLCacheTest.MainPage..ctor()}

I am Using:

  • Silverlight 5 RC, .NET 4
  • Visual Studio 2010
  • Enterprise Library 5 Silverlight Integration Pack

I made a default configuration with the entlib Configurator, but did not configure Unity.

THANKS!!

Oct 23, 2011 at 6:46 AM
Edited Oct 23, 2011 at 6:48 AM

Does your Silverlight project have a reference to System.Xml.Linq (it's not added by default)?  If not, then you should add a reference to the System.Xml.Linq.

I'm not sure exactly what you have done but the basic approach would be to create a XAML configuration and place it on the web site.

 

<?xml version="1.0" encoding="utf-8"?>
<el:ConfigurationDictionary 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="In-Memory Cache" x:Key="cachingSilverlightConfiguration">
        <el:CachingSettings.Caches>
            <el:InMemoryCacheData ExpirationPollingInterval="00:02:00" Name="In-Memory Cache" />
            <el:IsolatedStorageCacheData MaxSizeInKilobytes="5120" PercentOfQuotaUsedBeforeScavenging="50" PercentOfQuotaUsedAfterScavenging="20" ExpirationPollingInterval="00:01:00" Name="Isolated Storage Cache" />
        </el:CachingSettings.Caches>
    </el:CachingSettings>
</el:ConfigurationDictionary>

 Then your Silverlight application will download the XAML file and load the EnterpriseLibraryContainer:

var configUri = new Uri("/cacheConfig.xaml", UriKind.Relative);
EnterpriseLibraryContainer.ConfigureAsync(configUri);

After that you should be able to use the cache. I recommend watching Enterprise Library for Silverlight - Data Caching demo. The Stock Trader reference implementation is also useful.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com