Webassembly NullReferenceException when no rows returned

Hi,

I am running a query in WASM which may or may not return rows. In server side Blazor, I could just use .Any() on the results but in WASM it does not get this far because it gets a NullReferenceException at the ReadAsync<ODataServiceResult>() step.

How can I code smarter to avoid this error?

Hi @simon,

Can you double check what is null in your case? The response shows not be null and if it is we will need more info on how to reproduce it.

The response is {"@odata.context":"http://localhost:5000/odata/sforms2/$metadata#Studentinfos","value":[]}

The database is new and the table in question is currently empty (no rows) so the response is correct but of course there is nothing to read from value.

Hey @simon,

This is not null response - I'm unable to reproduce such exception with an empty table:




Interesting that you have an OData count in the response and I do not. I'm using PostgreSQL db but don't really see why that would make a difference.

Maybe I should add that I have a filter http://localhost:5000/odata/sforms2/Studentinfos?$filter=student_id+eq+%2790876321%27

Same with Postgre and filter:



without filter

So what have I done not to get the Odata.count?

Without a project where I can reproduce the problem I’m unable to provide any more info.

I understand. At least I can see that the Odata.count is a difference so I can dig a bit more around that at a later stage. Meanwhile, I'm going to push this project out as server side Blazor instead.

Hi, I tried a new WASM project on SQL Server this time and have a similar issue with NullReferenceException when there are no rows.

I captured the executed sql and it runs, retruning no rows as expected...

The response is again empty as before...

How can we investigate this further, there is obviously an issue.

Please send us your application along with your database as SQL script at info@radzen.com. You can use some sharing service like Google Drive, One Drive, etc.

Thanks. I have sent a One Drive link.