locked
saving file fails way too often. "WinRTError: unspecified error" when writing to roamingFolder

    Question

  • In our game Game Dev Tycoon, we have some straight forward code to save our game state into the roaming folder.

    var roamingFolder = Windows.Storage.ApplicationData.current.roamingFolder;
    
    roamingFolder.createFileAsync(name, Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {
    	Windows.Storage.FileIO.writeTextAsync(file, s).then(function () {
    		//code
    	}, error);
    }, error);

    In our own testing this nearly always works, only rarely do we get a "could not write error".

    Unfortunately from our game usage statistics I see that yesterday alone this method failed at least a whopping 480 times for our players! I know that it works for the majority of times but this is way too high of a number to just ignore as an exception.

    We have also heard from one player that they get an error message 'every' time they try to save. The error message is 'WinRTError: unspecified error'.

    Are there any known causes for this to consistently fail? Unfortunately this makes our game completely unplayable for this player and I suspect for others too.







    • Edited by PatrickKlug Thursday, December 13, 2012 4:42 PM
    Thursday, December 13, 2012 8:06 AM

All replies

  • Hi,

    Generally, the code as follow work normally on my side:

    Windows.Storage.ApplicationData.current.roamingFolder.createFileAsync("file.txt", Windows.Storage.CreationCollisionOption.replaceExisting)
            .then(function (file) {
                return Windows.Storage.FileIO.writeTextAsync(file, “Hello World!”);
            });
    

    But the error you said doesn't has any details. So could you reproduce that, and provide more details. I am not sure why happen so many times as you said.

    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 14, 2012 9:07 AM
  • No, I cannot reproduce it and unfortunately I don't have more info. Really could use some help on this. Is there something I can check with users who experience this? Are those errors somewhere logged in detail?
    Friday, December 14, 2012 11:06 AM
  • Hi,

    There is no error on my side. Please check again. And also debug with VS2012.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 2:39 AM
  • Hi Roy,

    There is no error on my side either. That's why I am asking for help! I cannot debug the issue because I cannot reproduce it but I know that it is happening for our users.

    As you can see the error message from the system is not helpful so I wonder how I can get to a more useful error information?

    Wednesday, December 19, 2012 2:45 AM
  • Hi,

     will involve more experts to investigate it. Any update will let you know.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 2:59 AM
  • Thanks Roy, much appreciated.
    Wednesday, December 19, 2012 3:01 AM
  • Hi Patrick,

    You can fail to roam the information if the size of the file is too big (but I believe it will still let you create the file).  Do you restrict the size of the file?  What is the maximum size of this data?

    See this:  http://msdn.microsoft.com/en-us/library/windows/apps/hh465094.aspx

    You will also need to add some logging to determine if the Create is failing or the Write is failing.  What OS is it failing on?

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, December 20, 2012 3:57 PM
    Moderator
  • Hi Jeff,

    The data is usually around 100-350KB so I don't think that should be an issue.

    I will add some more error logging into the app with the next update. Sadly, the Windows Store Dashboard has zero info on any errors, even though the app has been in there for 10 days now.

    Not sure what you mean with OS but the app is not available on ARM yet so it's either x86 or x64 Win8.

    Patrick

    Friday, December 21, 2012 10:06 AM
  • Patrick - did you add any error information to your logging?  If so, are you seeing any trends?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, January 8, 2013 8:57 PM
    Moderator
  • Hi Matt,

    Thanks for the follow up. We haven't included logging to distinguish the two methods yet but will do so in the next update.

    I have a player who says that he consistently receives this error. Are there any WinRT logs (event viewer) or something we can get from this user to identify the issue?

    Our analytics show that this exact same issue happens around 100(!) times a day for our users and seems to be the number one cause for errors.

    Patrick

    Thursday, January 17, 2013 12:52 AM
  • There are certainly event logs from the viewer that you can get but I do not know what data they will contain.  As we said previously, logging around that function call is going to be the best way to get the information needed to fix this.  Have you personally tested this on an RT device?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, January 17, 2013 2:39 PM
    Moderator
  • Yes, I have personally tested on an RT device but this issue is *not* related to RT. It happens on normal PC's. I know this because we observe the issue on our full game (Game Dev Tycoon) which is not available on RT.

    In the last update I was finally able to include some more tracking of this error:

    In the past 6 days saving a file has failed at least over 500(!) times for our users. 76% of the time the createFileAsync fails, the rest is the writeTextAsync method. We got some error codes but I was unable to find out what they mean:

    code		nr.	%
    -2147024891	383	75%
    -2147024864	51	10%
    -2147023721	41	8%
    -2147467259	19	4%
    -2147024894	17	3%


    I'm sure Microsoft has better statistics on how these methods fail. In any case, what is important is that some users report that saving always fails. Unfortunately we don't know how to help them. If you can provide some guidance in how we can improve this method or what the cause of this could be then please let me know. I doubt I'm the only one plagued by this.



    • Edited by PatrickKlug Tuesday, February 26, 2013 6:02 AM
    Tuesday, February 26, 2013 5:59 AM
  • Usually the best way is to convert these values to hex:

    -2147024891 = 80070005 = Access Denied - Sounds like a permissions problem.

    -2147024864 = 80070020 = Sharing Violation - The file is already in use when you're trying to do something with it.

    -2147023721 = 80070497 = Error Unable to Remove Replaced - "The replaced file could not be deleted. The replaced and replacement files retain their original file          names."

    -2147467259 = 80004005 = Fail  - Usually Access Denied.

    -2147024894 = 80070002 = File not found - sounds like the file isn't there to do something with it.

    I think this should be a good place to start understanding what's going on.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, February 27, 2013 2:32 PM
    Moderator
  • Hi Matt,

    Thanks. This is helpful in that it at least explains things a little more than 'Unspecified error'. Thanks for pointing to the error messages - I didn't think of converting the numbers.

    I do have to wonder though how one is supposed to write a simple save/load routine when the one I use fails as often. This doesn't happen once or twice but happens hundreds of times a day. 

    I'm especially baffled on how to deal with a 'Access Denied' error, which seems to be the error which happens most often. I mean this is the roamingFolder we're talking about here. What am I supposed to do? Expose to the user that the system is just incapable of handling file IO? Is there something wrong in the way I approach saving files?

    I seriously wonder how anyone else writes to the roamingFolder without having so many errors?

    Any insights appreciated.

    Tuesday, March 5, 2013 4:39 AM
  • Patrick,

    I've had issues like this when I was developing the logging portion of Eight.js. I found that Access Denied usually happens (I would guess) when WinJS has yet to release the lock on your file from a previous action. So my assumption is that if someone clicks the save button twice and the first save has not completed by the time the second save starts, you get access denied because the file is technically still in use by the previous save. The way I got around this was to queue up logging actions. You could presumably do the same thing, but key off of whatever file name it is you're trying to access.

    Does that sound plausible? That might at least explain some of your errors.

    Tuesday, March 5, 2013 4:52 AM
  • Like Patrick says, you might want to lock your file actions so they are sequentially executed.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, March 5, 2013 3:27 PM
    Moderator
  • That's definitely something I should do but I really doubt that this is the issue. We have our save button on the app bar. When you press it, the app bar hides itself and you see a 'Saving...' label. I really doubt that hundreds of times a day users would open up the app bar immediately again and press Save again.

    The only other function calling our save routine is our auto-save feature. It saves to a different file so it can't interfere with user actions and only fires every 10 seconds or so.

    Wednesday, March 6, 2013 12:16 AM
  • What about a load/read function on the same file? I think you need to take a look at any and all operations that could be accessing that file. I would bet a very pretty penny on the Access Denied error being because of file access locking because I've seen it so much myself.
    Wednesday, March 6, 2013 2:11 AM