.NET: Problem retrieving object with SortBy QueryOption

I need receive data just from Users table and sorted by one of the columns. let’s call it “SortField”.

i use the following method for it :

 public static BackendlessAPI.Data.BackendlessCollection<BackendlessAPI.BackendlessUser> GetUser(string whereClause, string property)
        {
            PersistenceService persistenceService = new PersistenceService();
            BackendlessDataQuery dataQuery = new BackendlessDataQuery(whereClause);
            dataQuery.Offset = 1;
            dataQuery.QueryOptions = new QueryOptions()
            {
                 SortBy = new List<string> { property }
                // internal weborb error appear 
            };
           //  dataQuery.Properties = new List<String> { property };
            BackendlessCollection<BackendlessUser> freeUsers = persistenceService.Find<BackendlessUser>(dataQuery);
            return freeUsers;
        }

when i remove SortBy option all works perfect. But when i execute query with SortBy = new List<string> { property } line, error inside of webord.dll appear “An unhandled exception of type ‘System.NullReferenceException’ occurred in weborb.dll” (see file attached.)
I specially applied part of code from your PersistenceServiceTest.cs
[TestMethod()] public void findWithSortByConditionTest() { string entityName = “Person”; //for (int i = 0; i < 15; i++) //{ // Dictionary<string, object> dict = new Dictionary<string, object>(); // dict.Add(“Name”, “test” + i); // dict.Add(“Age”, 20 + i); // persistenceService.Save(entityName, dict); //} try { BackendlessDataQuery query = new BackendlessDataQuery(); query.QueryOptions = new QueryOptions { SortBy = new List<string> { “Name” } }; var ps = persistenceService.Find<Person>(query); Assert.IsNotNull(ps); } catch (BackendlessException ex) { Assert.AreEqual(“adafa”, ex.Code); } }
and still receiving this error.

Hi Mike,

Could you please confirm if you’re using the latest SDK for .NET from our website?

Regards,
Mar

Btw, I just tried the following code with the latest assembly and it works just fine:

      BackendlessDataQuery dataQuery = new BackendlessDataQuery();
      dataQuery.Offset = 1;
      dataQuery.QueryOptions = new QueryOptions()
      {
        SortBy = new List&lt;string&gt; { "email" }
      };


      BackendlessCollection&lt;BackendlessUser&gt; freeUsers = Backendless.Data.Of&lt;BackendlessUser&gt;().Find( dataQuery );
      List&lt;BackendlessUser&gt; users = freeUsers.Data;


      foreach( BackendlessUser user in users )
      {
        System.Console.Out.WriteLine( user.Email );
      }

Thank you Mark,
I was using the latest .Net 4.0 assembly from Backendless For Developers | Backendless Backend as a Service Platform

I 've found the solution of this problem. The same error appear if you place weborb.config in any other place instead of bin/debug folder in console application.
In my case another library BackendlessApi.dll works with your sdk that have it’s own bin/debug folder, but it was wrong practice.
I am using MVC 4 application as start project, so there is only bin folder, and all config files should be placed right in project directory. After this applications work right.

weborrb.config.png

Hi Mike,

Yes, indeed, it needs to be present there. We need to figure out a way to alert the developer if the file is not found, or simply remove the need for the file.

Regards,
Mark