IsolatedStorage Exception

Jun 25, 2014 at 10:19 AM

I am using Adrotator v1.1.0-Beta for my WP7.1 app and I've been seeing sporadic "IsolatedStorage Exceptions" in the app and finally got a debug session showing what is happening.

The trace I got from Microsoft looks like this:

"Frame Image Function Offset
0 mscorlib_ni System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor 0x000001f2
1 mscorlib_ni System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor 0x0000002a
2 adrotator_ni AdRotator.AdRotatorControl.LoadAdSettings 0x00000096
3 adrotator_ni AdRotator.AdRotatorControl._FetchAdSettingsFile_b__18 0x0000013e
4 system_windows_ni System.Net.Browser.ClientHttpWebRequest+__c__DisplayClass1d._InvokeGetResponseCallback_b__1b 0x00000046
5 mscorlib_ni System.Threading.QueueUserWorkItemCallback.WaitCallback_Context 0x00000044
6 mscorlib_ni System.Threading.ExecutionContext.RunInternal 0x000000be
7 mscorlib_ni System.Threading.ExecutionContext.Run 0x00000010
8 mscorlib_ni System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem 0x00000054
9 mscorlib_ni System.Threading.ThreadPoolWorkQueue.Dispatch 0x000000ca
10 mscorlib_ni System.Threading._ThreadPoolWaitCallback.PerformWaitCallback 0x00000004"

When debugging I found that after I call AdRotator's Invalidate method this happens:

InvalidateAd gets called from Invalidate.
LoadAdSettings gets called from InvalidateAd.
FetchAdSettingsThreaded gets called from LoadAdSettings.
FetchAdSettingsThreaded spawns a call to FetchAdSettingsFile.
FetchAdSettingsFile starts to execute and on the same time OnApplyTemplate gets called.
OnApplyTemplate calls Invalidate, which calls InvalidateAd and via LoadAdSettings ends up in FetchAdSettingsThreaded too, and so FetchAdSettingsThreaded spawns another call to FetchAdSettingsFile.

Eventually the two threads have gotten the remote AD settings in FetchAdSettingsFile and will try to save them to Isolated Storage, which sometimes happens simultaneously causing an IsolatedStorage Exception.

I downloaded the source code and added a flag which I used to prohibit calling FetchAdSettingsFile twice and that seems to fix the problem.

Am I doing something wrong or is it a bug? Maybe I should try the V2 version instead?

Jun 25, 2014 at 11:19 AM
That does sound like a bit of a bug.

In V2 we don't call invalidate from OnApplyTemplate any more in the next update.

Although feel free to check the V2 source in my branch and see if you have any issue, fixes welcome.

I'd reccomment moving to V2 as we have nearly reached feature parity with V1 with the next release.