IsolatedStorage Errors
Asked Answered
G

4

7

I'm building a Windows Phone 7 application that uses isolated storage. The code works most of the time but I keep getting IsolatedStorageExceptions randomly:

{"An error occurred while accessing IsolatedStorage."}

There are no further details about the reason for the exception.  Here is the stack trace:

   at System.IO.IsolatedStorage.IsolatedStorageFile.DeleteFile(String file)
   at MyApp.Core.Data.WindowsPhoneFileRepository.DeleteFile(String name)
   at MyApp.Core.Domain.ThingService.SaveThing(Thing Thing)
   at MyApp.Core.Domain.TrackedThingService.PersistThingLocally(TrackedThing Thing)
   at MyApp.Ui.ViewModels.TrackViewModel.<.ctor>b__3(Thing Thing)
   at GalaSoft.MvvmLight.Command.RelayCommand`1.Execute(Object parameter)
   at GalaSoft.MvvmLight.Command.EventToCommand.Invoke(Object parameter)
   at System.Windows.Interactivity.TriggerAction.CallInvoke(Object parameter)
   at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
   at System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
   at System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

The file exists. I place all my IsolatedStorage uses inside using blocks so I shouldn't have the file open anywhere.

What could be causing this?

How I can I get more details about the cause of the exception?

Gradeigh answered 17/7, 2010 at 11:51 Comment(0)
C
7

Using blocks are currently not guaranteed to flush/close streams in WP7.

Close all files/streams explicitly until the SDK reaches the point you can actually trust it! :)

Cirrose answered 12/11, 2010 at 15:21 Comment(2)
Really? That explains so much! And now I must go, as I have a number of streams to close. Tell me I can trust Close to flush the stream?Chymotrypsin
@Peter Wone: Close is explicit, so you can trust it to do what it says on the tin. Using blocks implicitly close connections, usually, but the object must support it. Remember this is an old answer: as soon as someone confirms it has been fixed please add a comment here!Cirrose
H
2

I would specifically check to make sure that you've closed all readers and writers to anything within the File that you are trying to delete. I'm not saying that will definately fix it, but rather not being able to delete files that do exist tend to be caused by open files.

Haslett answered 26/9, 2010 at 17:30 Comment(0)
P
0

It should not be overlooked that the WP7 is still in Beta (you've updated from the CTP to the Beta version right?).

Consider creating a very simple application that manipulates the Isolated storage in the way your main application is to see if you can create a small Repo of the problem. Having done that send it to Microsoft so they can take a look at it.

Potto answered 17/7, 2010 at 18:24 Comment(2)
Yes, I have updated to beta version. I will do this as a last resort. Surely there is some way to get more details about the exception.Gradeigh
@Chief7: You have the debugger stop on the offending line when it happens?Potto
S
0

I faced the same problem.

I checked carefully and found a place where I didn't close the FileStream. Closing it solved the problem for me.

Stunning answered 3/4, 2013 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.