jamesmontemagno / monkey-cache

Easily cache any data structure for a specific amount of time in any .NET application.
MIT License
670 stars 106 forks source link

Operation is not valid due to the current state of the object #142

Closed vhakti closed 6 months ago

vhakti commented 6 months ago

Consider the following c# code:

private IBarrel _barrel; public FileMonkeyCacheService() {

 Barrel.ApplicationId = "any id..";
 _barrel = Barrel.Current;

}

when the application is starting in debug mode, the following exception is thrown on using Barrel instance object:

System.InvalidOperationException
  HResult=0x80073D54
  Message=**Operation is not valid due to the current state of the object.**
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
   at ABI.Windows.Storage.IApplicationDataStaticsMethods.get_Current(IObjectReference _obj)
   at Windows.Storage.ApplicationData.get_Current()
   at MonkeyCache.BarrelUtils.GetBasePath(String applicationId)
   at MonkeyCache.FileStore.Barrel.<>c__DisplayClass4_0.<.ctor>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at MonkeyCache.FileStore.Barrel.LoadIndex()
   at MonkeyCache.FileStore.Barrel..ctor(String cacheDirectory, HashAlgorithm hash)
   at MonkeyCache.FileStore.Barrel.get_Current()
   at HelperDll.Contracts.FileMonkeyCacheService..ctor() in ...

Context: A test Maui blazor app was configured to be deployed as an unpackaged application. So it is not using MSIX. the issue is happening only with this configuration. The default configuration with MSIX does not affect the application behaviour.

vhakti commented 6 months ago

Duplicated with #141