IsolatedStorageFileStream上不允许操作。 IsolatedStorage异常

时间:2014-08-01 12:17:19

标签: c# visual-studio-2013 silverlight-5.0

我是C#和Visual Studio的初学者。我已经构建了一个Silverlight应用程序,以便在播放器中获取自定义参数,以便在浏览器中播放视频。

下面给出了从浏览器运行应用程序的代码:

        // When running outside the browser, retrieve initParams from isolated storage.
        if (Application.Current.IsRunningOutOfBrowser)
        {
            using (IsolatedStorageFile file =
                IsolatedStorageFile.GetUserStoreForApplication())

            using (var stream = new IsolatedStorageFileStream(
                "initParams.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read, file))
            {
                // The serializer requires a reference to System.Runtime.Serialization.dll.
                DataContractSerializer serializer =
                    new DataContractSerializer(typeof(Dictionary<String, String>));
                initParams = (Dictionary<String, String>)serializer.ReadObject(stream);
            }
        }
        // Otherwise, save initParams to isolated storage.
        else
        {
            initParams = e.InitParams;

            using (IsolatedStorageFile file =
                IsolatedStorageFile.GetUserStoreForApplication())
            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(
                "initParams.txt", System.IO.FileMode.Create, file))
            {
                DataContractSerializer serializer =
                    new DataContractSerializer(typeof(Dictionary<string, string>));
                serializer.WriteObject(stream, initParams);
            }
        }

我收到错误,不允许操作。代码中的IsolatedStorage异常

            using (IsolatedStorageFile file =
                IsolatedStorageFile.GetUserStoreForApplication())

            using (var stream = new IsolatedStorageFileStream(
                "initParams.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read, file))

Visual Studio中的错误消息是

  

System.IO.IsolatedStorage.IsolatedStorageException:不是操作   在IsolatedStorageFileStream上允许。在   System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path,   FileMode模式,FileAccess访问,FileShare共享,Int32 bufferSize,   IsolatedStorageFile isf)at   System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path,   FileMode模式,FileAccess访问,IsolatedStorageFile isf)at   testplayer.App.LoadInitParams(StartupEventArgs e)at   testplayer.App.Application_Startup(Object sender,StartupEventArgs e)   在MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex,   委托handlerDelegate,Object sender,Object args)at   MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj,IntPtr   unmanagedObjArgs,Int32 argsTypeIndex,Int32 actualArgsTypeIndex,   String eventName,UInt32 flags)

任何人都可以帮我解决这个问题吗?

提前致谢

0 个答案:

没有答案