Enterprise Library caching

Topics: Caching Application Block
Jul 3, 2007 at 4:23 AM
I am getting an error "could not find file" in th following line

CacheManager cache = CacheFactory.GetCacheManager();

But the same code is working in other system.

This error i get when i am reading from cache. I am not getting this error while i am writing to the cache.



Please help me on this.

Please find the following error message.



System.IO.FileNotFoundException was unhandled
Message="Could not find file 'InboundLogistics\\-1208129235\\ScPr'."
Source="mscorlib"
FileName="InboundLogistics\\-1208129235\\ScPr"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageCacheItemField.Read(Boolean encrypted)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageCacheItem.Load()


Thanks in advance for your kindly help.





Regards,



Ramesh Babu
Jul 3, 2007 at 2:02 PM
Hi Ramesh,

Can you provide additional details about your configuration?

Also, you mention the you get an error when creating the CacheManager, but then you say that you get the error when reading but not when writting and you do need a properly created CacheManager for both operations. Please describe your scenario in more detail.

Fernando
Jul 3, 2007 at 9:51 PM
Hi Fernando
Please see the following config file and the .net code. In the .net code we are using the same class/method for both reading the data from cache and writing the data to cache.
so both reading/writing refers the same config file.
1. We are reading an object from cache
2. if the object is null , we are reading the data from dataProvider.GetInboundTrailerSearchValues() method and adding to the cache
3. else we are returing the object from cache.
Initially when the object is null we were able to read the data dataProvider.GetInboundTrailerSearchValues() method and could able to write to the cache. Second time when the code is executed in the line "CacheManager cache = CacheFactory.GetCacheManager()" we are getting this error.

I am struck up here for past 1 week. I am unable to proceed beyond this.

Thanks in advance for your valuable suggestion on this.

Please find the following config file.

<cachingConfiguration defaultCacheManager="Cache Manager">
<cacheManagers>
<add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000"
numberToRemoveWhenScavenging="10" backingStoreName="Isolated Storage"
name="Cache Manager" />
</cacheManagers>
<backingStores>
<add partitionName="InboundLogistics" encryptionProviderName=""
type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
name="Isolated Storage" />
</backingStores>
</cachingConfiguration>

Please see the following .net code

public class CacheData
{
public InboundTrailersRequest GetData()
{
InboundTrailersRequest request = null;

CacheManager cache = CacheFactory.GetCacheManager();
request = (InboundTrailersRequest)cache"InboundTrailers";

if (request == null)
{
CacheDataProvider dataProvider = new CacheDataProvider();
request = dataProvider.GetInboundTrailerSearchValues();

AbsoluteTime expiry = new AbsoluteTime(new TimeSpan(1, 0, 0, 0)); //1 day
cache.Add("InboundTrailers", request, CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry });
}

return request;
}
}

The full error is
System.IO.FileNotFoundException was unhandled
Message="Could not find file 'InboundLogistics\\-1208129235\\ScPr'."
Source="mscorlib"
FileName="InboundLogistics\\-1208129235\\ScPr"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageCacheItemField.Read(Boolean encrypted)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageCacheItem.Load()
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageBackingStore.LoadDataFromStore()
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.BaseBackingStore.Load()
at Microsoft.Practices.EnterpriseLibrary.Caching.Cache..ctor(IBackingStore backingStore, CacheCapacityScavengingPolicy scavengingPolicy, CachingInstrumentationProvider instrumentationProvider)
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheManagerFactoryHelper.BuildCacheManager(String cacheManagerName, IBackingStore backingStore, Int32 maximumElementsInCacheBeforeScavenging, Int32 numberToRemoveWhenScavenging, Int32 expirationPollFrequencyInSeconds, CachingInstrumentationProvider instrumentationProvider)
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheManagerCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUpTTypeToBuild(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUpT(IReadWriteLocator locator, IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.CreateDefault()
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager()
at Levi.LSA.USDistribution.Orion.InboundLogistics.CacheData.GetData() in D:\Orion\Development\SCSF\Source\InboundLogistics\Levi.LSA.USDistribution.Orion.InboundLogistics\CacheData.cs:line 16
at Levi.LSA.USDistribution.Orion.InboundLogistics.InboundTrailersSearchPresenter.GetDefaultValues() in D:\Orion\Development\SCSF\Source\InboundLogistics\Levi.LSA.USDistribution.Orion.InboundLogistics\Views\InboundTrailersSearchPresenter.cs:line 117
at Levi.LSA.USDistribution.Orion.InboundLogistics.InboundTrailersSearch.SetDefaultValues() in D:\Orion\Development\SCSF\Source\InboundLogistics\Levi.LSA.USDistribution.Orion.InboundLogistics\Views\InboundTrailersSearch.cs:line 59
at Levi.LSA.USDistribution.Orion.InboundLogistics.InboundTrailersSearch.OnLoad(EventArgs e) in D:\Orion\Development\SCSF\Source\InboundLogistics\Levi.LSA.USDistribution.Orion.InboundLogistics\Views\InboundTrailersSearch.cs:line 43
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Levi.LSA.USDistribution.Orion.InboundLogistics.ModuleController.ShowInboundTrailersSearchHandler(Object sender, EventArgs e) in D:\Orion\Development\SCSF\Source\InboundLogistics\Levi.LSA.USDistribution.Orion.InboundLogistics\ModuleController.cs:line 156
at Microsoft.Practices.CompositeUI.Commands.Command.OnExecuteAction(Object sender, EventArgs e)
at Microsoft.Practices.CompositeUI.Commands.CommandAdapter.FireCommand()
at Microsoft.Practices.CompositeUI.Commands.EventCommandAdapter`1.InvokerEventHandler(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
Jul 3, 2007 at 11:51 PM
Edited Jul 3, 2007 at 11:55 PM
Hi Ramesh,

Is this second invocation fired from a new process? If not, the fact that the cache manager is being built for a second time would show some strange issue.

It would be great if you could come out with a very short, self contained repro (no foreign code, just a short console app that shows the problem).

Fernando
Aug 27, 2007 at 1:17 PM
Hi,

Have you managed to find a solution to this problem?
We are also getting the error when we try to retrieve information from the cache, this is the code that we are using.

CacheManager cacheMngr = CacheFactory.GetCacheManager(RecentListCacheName);
string listKey = string.Format(RECENTLIST_KEY);

List<Info> list = cacheMngrlistKey as List<Info>;
return list ?? new List<Info>();

Any help would be greatly appreciated

Robert
Aug 27, 2007 at 4:50 PM
The issue is solved for me.
The reason is because the Isolated storage file is corrupted.
Twice the file got corrupted for me in the development environment (seems to be some small bug in the Enterprise library caching).

There are two reolutions
1. Change the partition name in the config file or
2. Delete the isolated storage file. By default It is saved in the following path (This path might vary for different systems) .

C:\Documents and Settings\<USERID>\Local Settings\Application Data\IsolatedStorage\zpcgstym.dkm\hfygkqz1.3kz\Url.wq2vsxxfrrd2gyoiqpekzdwz0ljitevm\Url.ovb2f5tgpjnvzx3veawbq1dj4fudgkpr\Files

You can find the actual path in the cachemanger object. If you can dig deep into the cachemanager object (using quick watch) you can find the actual path where the cache is stored in the hard drive.

Please let me know if you need any other information.


Thanks

Ramesh Babu

Aug 27, 2007 at 5:33 PM
Hi,


robobrown wrote:
Hi,

Have you managed to find a solution to this problem?
We are also getting the error when we try to retrieve information from the cache, this is the code that we are using.

CacheManager cacheMngr = CacheFactory.GetCacheManager(RecentListCacheName);
string listKey = string.Format(RECENTLIST_KEY);

List<Info> list = cacheMngrlistKey as List<Info>;
return list ?? new List<Info>();

Any help would be greatly appreciated

Robert


Do you get this error consistently, or does it happen randomly?

Regards,
Fernando
Aug 27, 2007 at 6:11 PM
This error is applicable only if the storage type for caching is Isolated storage.
The issue is solved for me.
I got the error only in my system.

There are two resolutions
1. Change the partition name in the config file or
2. Delete the isolated storage file. By default the file is saved in the following path (This path might vary for different systems) .

C:\Documents and Settings\<USERID>\Local Settings\Application Data\IsolatedStorage\zpcgstym.dkm\hfygkqz1.3kz\Url.wq2vsxxfrrd2gyoiqpekzdwz0ljitevm\Url.ovb2f5tgpjnvzx3veawbq1dj4fudgkpr\Files

You can find the actual path in the cachemanger object. If you can dig deep into the cachemanager object (using quick watch) you can find the actual path where the cache is stored in the hard drive.

Thanks

Ramesh Babu
Aug 27, 2007 at 7:29 PM
Here are a few more details about this bug.

I have tried deleting the isolated storage files and this does not seem to help.

The error happens randomly and once it happens it will continue to happen until you restart the application. Once the error occurs the cache gets cleared.
I have tried changing the partition name to something else and this still does not help (in the long run).
I also have three different partitions in the cache manager settings whose functionality does not overlap.

I also do not get the error in the development environment, the testing environment computers are however locked down to the user but im sure this will not affect this error.

Thanks

Robert Brown
Aug 27, 2007 at 7:37 PM
Could this error be caused by special characters in the objects that im saving in the cache?
Aug 27, 2007 at 8:30 PM
Hi,

Which version of Enterprise Library are you using? From version 3.0, IO errors while loading the cache will cause the item to be ignored, so this particular exception shouldn't bubble up to the app code:

System.IO.FileNotFoundException was unhandled
Message="Could not find file 'InboundLogistics\\-1208129235\\ScPr'."
Source="mscorlib"
FileName="InboundLogistics\\-1208129235\\ScPr"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageCacheItemField.Read(Boolean encrypted)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageCacheItem.Load()
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageBackingStore.LoadDataFromStore()

Robert, do you see the same stack?

Fernando
Aug 27, 2007 at 9:08 PM
This is the stack trace that i have and we are using enterprise library version 3.1



Message: Could not find file 'SmartClient\644272505\LA'.
At:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageCacheItemField.Overwrite(Object itemToWrite)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageCacheItem.UpdateLastAccessedTime(DateTime newTimestamp)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageBackingStore.UpdateLastAccessedTime(Int32 storageKey, DateTime timestamp)
at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.BaseBackingStore.UpdateLastAccessedTime(String key, DateTime timestamp)
at Microsoft.Practices.EnterpriseLibrary.Caching.Cache.GetData(String key)
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager.get_Item(String key)
Aug 28, 2007 at 2:55 PM
Hi,

Thanks for the update Robert. From what I can see the fix to cleanup the store when files are missing only works when loading, not when updating; I'm logging this as a problem.

I can imagine how using the file system to store the cache informamtion can be problematic if more than one app domain is trying to manage the same set of files. How is your test environment set up? Do you have multiple worker process?

Regards,
Fernando
Aug 28, 2007 at 4:45 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 21, 2008 at 8:23 AM
Edited Jun 2, 2008 at 7:44 AM