Compiler Bug or Corrupt System: exception in GetFoldersAsyn()???
-
2012년 8월 7일 화요일 오후 5:51
The code below had been working just fine until a couple days ago. Now, the line GetFolderAsync() produces this exception:
Value does not fall within the expected range.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()What is really puzzling is that this method works OK in a test app, like EnumerateFolder sample but causes the above exception in my "real" app. So, does that mean my system is corrupt or is there a problem with Visual Studio?????
And in my "real" app, if I replace GetFoldersAsync() with GetFilesAsync() there is no exception. All of the files are returned as expected, just not in groups.
Any Ideas?
private async void EnumerateFolder() { var folderPicker = new Windows.Storage.Pickers.FolderPicker(); folderPicker.SuggestedStartLocation = PickerLocationId.Desktop; folderPicker.FileTypeFilter.Add(".xml"); folderPicker.FileTypeFilter.Add(".txt"); folderPicker.FileTypeFilter.Add(".gpx"); StorageFolder picturesFolder = await folderPicker.PickSingleFolderAsync(); if (picturesFolder != null) { // Application now has read/write access to all contents in the picked folder (including other sub-folder contents) StorageFolderQueryResult queryResult = picturesFolder.CreateFolderQueryWithOptions(new QueryOptions(CommonFolderQuery.GroupByMonth)); IReadOnlyList<StorageFolder> folderList = await queryResult.GetFoldersAsync(); foreach (StorageFolder folder in folderList) { IReadOnlyList<StorageFile> fileList = await folder.GetFilesAsync(); System.Diagnostics.Debug.WriteLine(folder.Name + " (" + fileList.Count + ")"); foreach (StorageFile file in fileList) { System.Diagnostics.Debug.WriteLine(file.Name + "-" + file.DateCreated.ToString()); } } } }
- 편집됨 Bucolic Geek 2012년 8월 10일 금요일 오후 5:38 better example
- 편집됨 Bucolic Geek 2012년 8월 10일 금요일 오후 5:42 Additional details
모든 응답
-
2012년 8월 7일 화요일 오후 7:44You'll probably need to provide the InnerException data for us to explain what exactly is going on.
-
2012년 8월 7일 화요일 오후 8:50Inner exception is Null.
-
2012년 8월 8일 수요일 오후 2:06
In an unrelated section of code, I ran into a "Wrong Thread" exception. So, as a shot-in-the-dark, I wrapped the offending GetFolderAsync in:
await App._cd.RunAsync(CoreDispatcherPriority.Normal, async () => {...}For what its worth, this made no difference at all to the exception being raised.
I also tried picking a different directory for the FutureAccessList and that also made no difference.
Any ideas on other things to try for debugging this?
Thanks,
Rick
-
2012년 8월 8일 수요일 오후 2:11Debugging unhandled exceptions that are raised off of the UI thread are a pain in the neck. One thing that I think you should try is to wrap the entire async method in a generic exception handler, then set a breakpoint at the catch statement. That will allow you to trap everything in the access thread and examine it before it takes down the worker thread.
-
2012년 8월 8일 수요일 오후 3:51
Perhaps I don't understand your suggestion. The section of code containing GetFolderAsync was already in a try/catch block. I added an outer try/catch around the entire async method. But, the inner (original) catch hits a breakpoint.
Are you suggesting that the exception is caused by a different thread and not really caused by GetFolderAsync???
Thanks,
Rick
-
2012년 8월 8일 수요일 오후 5:18I was hoping to tease out a more instructive stack trace than what was provided, which is just threading stuff that throws back to the caller. I can't see anything obviously wrong with the code as posted; perhaps you could post the entire method in which this snippet resides?
-
2012년 8월 8일 수요일 오후 7:01
OK I added my code to one of the samples. In the File Access Sample, scenario 6, I added code to the "Show List" button event handler. Here is the entire event handler. The code I added is after if ( FALRadioButton...
I think you can replace the existing method in scenario6.xaml.cs, adding a couple "usings" and run the sample. Debug break at the Try block and run the sample. Select scenario 6, click Frequent Access List radio button, and click Show List. On my development system (the \\Build tablet) I get the exception described previously at the GetFolderAsync line.
private async void ShowListButton_Click(object sender, RoutedEventArgs e) { StorageFile file = rootPage.sampleFile; if (file != null) { if (MRURadioButton.IsChecked.Value) { AccessListEntryView entries = StorageApplicationPermissions.MostRecentlyUsedList.Entries; if (entries.Count > 0) { StringBuilder outputText = new StringBuilder("The MRU list contains the following item(s):" + Environment.NewLine + Environment.NewLine); foreach (AccessListEntry entry in entries) { outputText.AppendLine(entry.Metadata); // Application previously chose to store file.Name in this field } OutputTextBlock.Text = outputText.ToString(); } else { OutputTextBlock.Text = "The MRU list is empty, please select 'Most Recently Used' list and click 'Add to List' to add a file to the MRU list."; } } else if (FALRadioButton.IsChecked.Value) { var folderPicker = new Windows.Storage.Pickers.FolderPicker(); folderPicker.SuggestedStartLocation = PickerLocationId.Desktop; folderPicker.FileTypeFilter.Add(".xml"); folderPicker.FileTypeFilter.Add(".txt"); folderPicker.FileTypeFilter.Add(".gpx"); StorageFolder folder = await folderPicker.PickSingleFolderAsync(); if (folder != null) { // Application now has read/write access to all contents in the picked folder (including other sub-folder contents) StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder); OutputTextBlock.Text = "Picked folder: " + folder.Path+" "+folder.Name; } else { OutputTextBlock.Text = "Operation cancelled."; } AccessListEntryView entries = StorageApplicationPermissions.FutureAccessList.Entries; if (entries.Count > 0) { StringBuilder outputText = new StringBuilder("The FAL list contains the following item(s):" + Environment.NewLine + Environment.NewLine); foreach (AccessListEntry entry in entries) { outputText.AppendLine(entry.Token); outputText.AppendLine(entry.Metadata); // Application previously chose to store file.Name in this field } OutputTextBlock.Text = outputText.ToString(); StorageItemAccessList mylist = StorageApplicationPermissions.FutureAccessList; var myfolder = await mylist.GetFolderAsync("PickedFoldertoken"); if (myfolder != null) { outputText = new StringBuilder("Folder contents: "+myfolder.Name + "\n"); IReadOnlyList<StorageFile> fileLists = await myfolder.GetFilesAsync(); foreach (StorageFile dfile in fileLists) { outputText.AppendLine(" " + dfile.Name); } OutputTextBlock.Text = outputText.ToString(); } //------------- // this is the problem code // Exception cause by GetFolderAsync() try { StorageFolderQueryResult queryResult = myfolder.CreateFolderQueryWithOptions(new QueryOptions(CommonFolderQuery.GroupByMonth)); IReadOnlyList<StorageFolder> folderList = await queryResult.GetFoldersAsync(); foreach (StorageFolder qfolder in folderList) { outputText.AppendLine("Folder:" + qfolder.DisplayName); } } catch (Exception ex) { outputText.AppendLine("Exception: " + ex.Message); } } else { OutputTextBlock.Text = "The FAL list is empty, please select 'Future Access List' list and click 'Add to List' to add a file to the FAL list."; } } } } -
2012년 8월 10일 금요일 오후 6:03
I think I figured out the problem. No its not a corrupt system and not a compiler bug. I think the problem is just from the path chosen to the desired disk directory. After researching QueryOptions, I found that we are supposed to check if query options are available with code like this:
QueryOptions myopts = new QueryOptions(CommonFolderQuery.GroupByMonth); bool test = picturesFolder.AreQueryOptionsSupported(myopts); System.Diagnostics.Debug.WriteLine("QueryOptions support:"+test);Then I found that depending on whether a Library was used or a path like "Computer c:\ ..." makes a difference. Drilling down using Libraries allows folder queries but using a path from "Computer" does not. So, it appears we need to build this test into any app where the user can pick a folder and we want to use common folder query.
thanks,
Rick
- 답변으로 표시됨 Bucolic Geek 2012년 8월 10일 금요일 오후 6:03

