Hellllooooo guys!
I have an app for Windows Phone 8. The crash report of my app lists one really big bug that often occurs (crash count is high). The funny (let's say sad) thing is that I can't reproduce this error on my phone or emulator. Can you help me, please?
The error is:
problem function: MyAppName.More+_writeToFile_d__11.MoveNext
exception type: system.unauthorizedaccessexception
stacktrace: "Frame Bild Funktion Offset
0 mscorlib_ni
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
0x0023a00e
1 mscorlib_ni
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
0x0000003a
2 mscorlib_ni System.Runtime.CompilerServices.TaskAwaiter_
[[System.__Canon,_mscorlib]].GetResult 0x0000001c
3 myAppName_ni
MyAppName.More+_writeToFile_d__11.MoveNext
0x000001cc
4 mscorlib_ni
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
0x0023a00e
5 mscorlib_ni
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
0x0000003a
6 mscorlib_ni
System.Runtime.CompilerServices.TaskAwaiter.GetResult
0x0000001a
7 myAppName_ni
MyAppName.More+_readFile_d__1b.MoveNext
0x000002f8
8 mscorlib_ni
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
0x0023a00e
9 mscorlib_ni
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
0x0000003a
10 mscorlib_ni
System.Runtime.CompilerServices.TaskAwaiter.GetResult
0x0000001a
11 myAppName_ni
MyAppName.MainPage+_buttonLike_Click_d__60.MoveNext
0x0000073e
12 mscorlib_ni
System.Runtime.CompilerServices.AsyncMethodBuilderCore._ThrowAsync_b__0 0x00000036"
I am using the method "writeToFile" like this:
await readFile();
await writeToFile((pointsCount + 200).ToString());
await readFile();
The method "writeToFile" is this one:
public static async Task writeToFile(string text)
{
// Get the text data from the parameter.
byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(text.ToCharArray());
// Get the local folder.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Create a new folder name DataFolder.
var dataFolder = await local.CreateFolderAsync("DataFolder",
CreationCollisionOption.OpenIfExists);
// Create a new file named DataFile.txt.
var file = await dataFolder.CreateFileAsync("DataFile.txt",
CreationCollisionOption.ReplaceExisting);
// Write the data from the parameter.
using (var s = await file.OpenStreamForWriteAsync())
{
s.Write(fileBytes, 0, fileBytes.Length);
}
}
The method "readFile" is this:
public static async Task readFile()
{
// Get the local folder.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
if (local != null)
{
if (Directory.Exists(local.Path + @"\DataFolder"))
{
// Get the DataFolder folder.
var dataFolder = await local.GetFolderAsync("DataFolder");
if (File.Exists(dataFolder.Path + @"\DataFile.txt"))
{
// Get the file.
var file = await dataFolder.OpenStreamForReadAsync("DataFile.txt");
if (file.Length > 0)
{
// Read the data.
using (StreamReader streamReader = new StreamReader(file))
{
pointsCount = Convert.ToInt32(streamReader.ReadToEnd());
}
}
else
{
await writeToFile("0");
await readFile();
}
}
else
{
await writeToFile("0");
await readFile();
}
}
else
{
await writeToFile("0");
await readFile();
}
}
}
User contributions licensed under CC BY-SA 3.0