Answered by:
getFileAsync to crash in installed package (local)

Question
-
When I launch app by VisualStudio my app work normally.
But after create package and installed it, my app was crashed. I tracing a lot of lines of code and found point before crash:
Windows.Storage.FileIO.readTextAsync(file, encod).done( ...
What is this bug and what may be workaround?Thursday, October 3, 2013 4:40 PM
Answers
-
Thanks for the replies guys!
I found the cause of my error.
First, I added a function to the error handler for done:
Windows.Storage.FileIO.readTextAsync(file, encod).done( function (arg) {... }, function (err){...})
and got the wrong message about the file's path (now the crash was not!).
Then I checked the path of the file in VS and was very surprised. The path was not correct, but nevertheless worked! (double slash):
"\\pic\description.xml"
When I corrected the way, it worked everywhere.
However strange the way that the error in the output above, led to the collapse of the handler below.
var encod = Windows.Storage.Streams.UnicodeEncoding.utf8 Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(path).then( // real error here! function (file) { Windows.Storage.FileIO.readTextAsync(file, encod).done( function (arg) { // complete }, function (err){ // mirror of error here! } ) } )
Tip: add error handlers where you can!- Marked as answer by chingachgoog Tuesday, October 8, 2013 2:21 PM
Tuesday, October 8, 2013 2:20 PM
All replies
-
NB!
If .done(null) - working without crash
if .done(function(){}) - crash again
(by VS always working without crash)Thursday, October 3, 2013 4:58 PM -
I had a similar problem with loadasync.
Sometimes it fails for no obvious reason and hangs the pc.
I found I had to trap out any exceptions and return a value decoding whether the laod was good or caused an exception.
n.Wright
Saturday, October 5, 2013 9:01 PM -
Hi chingachgoog,
I will try it and update you the result later.
Best Regards,
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Monday, October 7, 2013 2:17 AMModerator -
Hi chingachgoog,
I cannot reproduce the issue you are facing.
I download a sample from MSDN code:File access sample (Windows 8). You could also try this sample, scenario two has the following JavaScript code which include readTextAsync and also .done() method:
function readText() { if (SdkSample.sampleFile !== null) { Windows.Storage.FileIO.readTextAsync(SdkSample.sampleFile).done(function (fileContent) { var outputDiv = document.getElementById("output"); outputDiv.innerHTML = "The following text was read from '" + SdkSample.sampleFile.name + "':<br /><br />" + fileContent; }, function (error) { WinJS.log && WinJS.log(error, "sample", "error"); }); } }
I create a app package for this sample and install on my PC, run it and I did not see any crash happens.
Could you try to give us a demo for a better support? Or do I misunderstanding something?
Best Regards,
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Monday, October 7, 2013 3:06 AMModerator -
Thanks for the replies guys!
I found the cause of my error.
First, I added a function to the error handler for done:
Windows.Storage.FileIO.readTextAsync(file, encod).done( function (arg) {... }, function (err){...})
and got the wrong message about the file's path (now the crash was not!).
Then I checked the path of the file in VS and was very surprised. The path was not correct, but nevertheless worked! (double slash):
"\\pic\description.xml"
When I corrected the way, it worked everywhere.
However strange the way that the error in the output above, led to the collapse of the handler below.
var encod = Windows.Storage.Streams.UnicodeEncoding.utf8 Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(path).then( // real error here! function (file) { Windows.Storage.FileIO.readTextAsync(file, encod).done( function (arg) { // complete }, function (err){ // mirror of error here! } ) } )
Tip: add error handlers where you can!- Marked as answer by chingachgoog Tuesday, October 8, 2013 2:21 PM
Tuesday, October 8, 2013 2:20 PM