none
Input string was not in correct format RRS feed

  • Question

  • Hi

    It's an UWP project  i get the exception "Input string was not in correct format" 

    when the compiler executes these  lines

     Try
                Dim folder As Windows.Storage.StorageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFoldersAsync("Assets")
                
            Catch ex As Exception
                Dim mes As New MessageDialog(ex.Message)
            End Try

    Thanks

    Wednesday, January 29, 2020 5:55 PM

Answers

  •         I succeeded by using method GetFolderAsync

    Private mediapl As New MediaElement
    
    Private Async Sub InitMedia()
            Try
                Dim folder As Windows.Storage.StorageFolder = Await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets")
                Dim file As Windows.Storage.StorageFile
                file = Await folder.GetFileAsync("alarm.wav")
                mediapl.SetSource(Await file.OpenAsync(Windows.Storage.FileAccessMode.Read), file.ContentType)
            Catch ex As Exception
                Dim mes As New MessageDialog(ex.Message)
            End Try
        End Sub

    • Marked as answer by Shay_w Friday, January 31, 2020 12:12 AM
    Thursday, January 30, 2020 6:12 PM

All replies

  • Hi,

    actually you are calling an async method without awaiting it, thus the result is not a StorageFolder object but an IAsyncOperation(Of StorageFolder) , you can Await it or just call GetResults() method: 

     Try
        ' I think that you should Await the method call to have the return type as StorageFolder object
        Dim folder As Windows.Storage.StorageFolder = 
                Await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFoldersAsync("Assets")
        ' or simply 
       folder = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFoldersAsync("Assets").GetResults()
     Catch ex As Exception
        Dim mes As New MessageDialog(ex.Message)
     End Try

    Best regards.

    Wednesday, January 29, 2020 6:25 PM
  • Hi

    I still get the same error the purpose is to play a wav file when a button is clicked

    Private Async Sub InitMedia()
            Try
                Dim folder As Windows.Storage.StorageFolder = Await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFoldersAsync("Assets")
                Dim file As Windows.Storage.StorageFile = folder.GetFileAsync("alarm.wav")
                mediapl.SetSource(file.OpenAsync(Windows.Storage.FileAccessMode.Read), file.ContentType)
            Catch ex As Exception
                Dim mes As New MessageDialog(ex.Message)
            End Try
        End Sub

    Wednesday, January 29, 2020 7:17 PM
  • you should just pay attention to asynchronous methods, you should call them using Await or call the GetResults() method on them:

    this time the error should be at this line :

    Dim file As Windows.Storage.StorageFile = Await folder.GetFileAsync("alarm.wav")
    
    'or 
    Dim file As Windows.Storage.StorageFile = folder.GetFileAsync("alarm.wav").GetResults();
    

    Wednesday, January 29, 2020 8:36 PM
  • Hi

    I still get the same error the purpose is to play a wav file when a button is clicked

    Private Async Sub InitMedia()
            Try
                Dim folder As Windows.Storage.StorageFolder = Await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFoldersAsync("Assets")
                Dim file As Windows.Storage.StorageFile = folder.GetFileAsync("alarm.wav")
                mediapl.SetSource(file.OpenAsync(Windows.Storage.FileAccessMode.Read), file.ContentType)
            Catch ex As Exception
                Dim mes As New MessageDialog(ex.Message)
            End Try
        End Sub

    I don't have a answer but can say this is not from an asynchronous call. A good guess is from reading the documentation a enum is used and your code is not using an enum

    https://docs.microsoft.com/en-us/uwp/api/windows.storage.storagefolder.getfoldersasync

    using Windows.Storage;
    using Windows.Storage.Search;
    using System.Threading.Tasks;
    using System.Diagnostics; // For writing results to Output window.
    
    // Get the user's Pictures folder.
    // Enable the corresponding capability in the app manifest file.
    StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
    
    // Get the files in the subfolders of the user's Pictures folder,
    // grouped by month. Get only the first 4 folders (months).
    IReadOnlyList <StorageFolder> groupedItems = await picturesFolder.GetFoldersAsync(CommonFolderQuery.GroupByMonth, 0, 4);
    
    // Iterate over the results and print the list of folders
    // and files to the Visual Studio Output window.
    foreach (StorageFolder folder in groupedItems)
    {
        Debug.WriteLine(folder.Name);
    
        // To iterate over the files in each folder, uncomment the following lines. 
        // foreach(StorageFile file in await folder.GetFilesAsync())
        //    Debug.WriteLine(" " + file.Name);
    }


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, January 29, 2020 9:30 PM
    Moderator
  •         I succeeded by using method GetFolderAsync

    Private mediapl As New MediaElement
    
    Private Async Sub InitMedia()
            Try
                Dim folder As Windows.Storage.StorageFolder = Await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets")
                Dim file As Windows.Storage.StorageFile
                file = Await folder.GetFileAsync("alarm.wav")
                mediapl.SetSource(Await file.OpenAsync(Windows.Storage.FileAccessMode.Read), file.ContentType)
            Catch ex As Exception
                Dim mes As New MessageDialog(ex.Message)
            End Try
        End Sub

    • Marked as answer by Shay_w Friday, January 31, 2020 12:12 AM
    Thursday, January 30, 2020 6:12 PM