2012-02-02 20 views
7

मेरी लाइब्रेरी अलग भंडारण का उपयोग कर रही है लेकिन मांग पर ही ऐसा करती है। तो मैं Lazy<T> का उपयोग कर रहा हूँ।आलसी भंडारण अलग-अलग भंडारण

हालांकि, इस फेंकता है:

System.IO.IsolatedStorage.IsolatedStorageException "विधानसभा के लिए दी गई अनुमति निर्धारण करने में असमर्थ।"

क्या आलसी थ्रेड के साथ अजीब कुछ करता है जो पृथक भंडारण प्रारंभिकता को भ्रमित करता है?

नमूना कोड:

using System; 
using System.IO.IsolatedStorage; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      var thisWorks = IsolatedStorageFile.GetMachineStoreForAssembly(); 
      thisWorks.Dispose(); 

      var lazyStorage = new Lazy<IsolatedStorageFile>(IsolatedStorageFile.GetMachineStoreForAssembly); 

      var thisFails = lazyStorage.Value; 
      thisFails.Dispose(); 
     } 
    } 
} 

पूर्ण स्टैक ट्रेस: ​​

System.IO.IsolatedStorage.IsolatedStorageException was unhandled 
    Message=Unable to determine granted permission for assembly. 
    Source=mscorlib 
    StackTrace: 
    Server stack trace: 
     at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) 
     at System.IO.IsolatedStorage.IsolatedStorageFile.GetMachineStoreForAssembly() 
     at System.Lazy`1.CreateValue() 
    Exception rethrown at [0]: 
     at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) 
     at System.IO.IsolatedStorage.IsolatedStorageFile.GetMachineStoreForAssembly() 
     at System.Lazy`1.CreateValue() 
     at System.Lazy`1.LazyInitValue() 
     at System.Lazy`1.get_Value() 
     at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Andrew Davey\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs:line 19 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 

उत्तर

6

ऐसा लगता है कि यह है क्योंकि आप (बल्कि एक प्रतिनिधि/लैम्ब्डा सीधे से) एक MethodGroup में गुजर रहे हैं, और यह नहीं कर पाता है यह पता लगाएं कि मूल रूप से कॉल कहां से आया था। यदि आप इसे इस पर स्विच करते हैं:

var lazyStorage = new Lazy<IsolatedStorageFile>(() => IsolatedStorageFile.GetMachineStoreForAssembly()); 

यह ठीक काम करना चाहिए।

संबंधित मुद्दे