locked
Not all code return a value in lambda expression error

    Question

  • Dear all,

    I am getting made with a wierd error.

    I am using SQLite in a WinRT application and open a db connection as below :

     private async Task InitializeAsync()
            {
                if (_connectionAsync == null)
                {
                    string databaseFile = _storageService.GetPathForFile("App.sqlite");
                    _connectionAsync = new SQLite.Net.Async.SQLiteAsyncConnection(() =>
                    {
                        new SQLiteConnectionWithLock(_sqlitePlatform, new SQLiteConnectionString(databaseFile, false));
                    });
    
                }
                await GetAddressTypeAsync();
            }

    Compiler return following error :

    "Not all code paths return a value in lambda expression of type 'System.Func<SQLite.Net.SQLiteConnectionWithLock>'"

    Where is this mistake hidden, I am blind

    Thnaks for help

    regards

    Tuesday, April 7, 2015 3:01 PM

Answers

  • Your lambda isn't returning anything, try:

    (() =>
                    {
                        return new SQLiteConnectionWithLock(_sqlitePlatform, new SQLiteConnectionString(databaseFile, false));
                    });
    

    or

    (() => new SQLiteConnectionWithLock(_sqlitePlatform, new SQLiteConnectionString(databaseFile, false)));
    


    http://peted.azurewebsites.net/

    • Marked as answer by wakefun Tuesday, April 7, 2015 4:39 PM
    Tuesday, April 7, 2015 4:33 PM