Error with Radzen.HttpResponseMessageExtensions.ReadAsync

When I get the response from an endpoint it throws this error:

Message: The requested operation requires an element of type 'Object', but the target element has type 'Array'.
Source: System.Text.Json.Rethrowable
StackTrace: at System.Text.Json.ThrowHelper.ThrowJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType)
at System.Text.Json.JsonDocument.CheckExpectedType(JsonTokenType expected, JsonTokenType actual)
at System.Text.Json.JsonDocument.TryGetNamedPropertyValue(Int32 index, ReadOnlySpan1 propertyName, JsonElement& value) at System.Text.Json.JsonElement.TryGetProperty(ReadOnlySpan1 propertyName, JsonElement& value)
at System.Text.Json.JsonElement.TryGetProperty(String propertyName, JsonElement& value)
at Radzen.HttpResponseMessageExtensions.d__01[[Radzen.ODataServiceResult1[[LunaAba.Server.Models.Consulta.ProfissionaisView, LunaAba.Client, Version=, Culture=neutral, PublicKeyToken=null]], Radzen.Blazor, Version=, Culture=neutral, PublicKeyToken=null]].MoveNext()
at LunaAba.Client.ConsultaService.GetProfissionaisViewsNotInAprendiz(Nullable1 aprendiz, String filter, String orderby, String expand, Nullable1 top, Nullable1 skip, Nullable1 count, String format, String select) in D:\Projetos\luna_aba\sistemas\lunaAba\Client\Services\ConsultaService.Custom.cs:line 102
at LunaAba.Client.Pages.SelectProfissionais.Grid0LoadData(LoadDataArgs args) in D:\Projetos\luna_aba\sistemas\lunaAba\Client\Pages\SelectProfissionais.razor.cs:line 97


[EnableQuery(MaxExpansionDepth = 10, MaxAnyAllExpressionDepth = 10, MaxNodeCount = 1000)]
public IActionResult GetProfissionaisNotInAprendiz([FromODataUri] int aprendiz)
//var query = consultaService.GetProfissionaisViewsNotInAprendiz(aprendiz);

        String wcStr = " a.Pessoa not in ("
                    + " Select pa.Profissional "
                    + " from ProfissionaisAprendizes pa "
                    + " where pa.Aprendiz = " + aprendiz.ToString() + ")"
                    + " And a.Pessoa in ("
                    + " Select fp1.Pessoa "
                    + " from FiliaisPessoas fp1 "
                    + " join FiliaisPessoas fp2 on fp1.Filial = fp2.Filial and fp1.Pessoa <> fp2.Pessoa "
                    + " where fp2.Pessoa = " + aprendiz.ToString() + ")";

        var query = context.ProfissionaisViews.FromSqlRaw(" select * from ProfissionaisView a where " + wcStr).ToList().AsQueryable();
        //var query = context.ProfissionaisViews.ToList().AsQueryable();

        return Ok(query);

Service method in client:

public async System.Threading.Tasks.Task<Radzen.ODataServiceResult<LunaAba.Server.Models.Consulta.ProfissionaisView>> GetProfissionaisViewsNotInAprendiz(int? aprendiz = default(int?), string filter = default(string), string orderby = default(string), string expand = default(string), int? top = default(int?), int? skip = default(int?), bool? count = default(bool?), string format = default(string), string select = default(string))
var uri = new Uri(baseUri, $"ProfissionaisViews/GetProfissionaisNotInAprendiz(aprendiz={aprendiz})");
uri = Radzen.ODataExtensions.GetODataUri(uri: uri, filter: filter, top: top, skip: skip, orderby: orderby, expand: expand, select: select, count: count);

        var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri);

        var response = await httpClient.SendAsync(httpRequestMessage);

        if (!response.IsSuccessStatusCode)
            throw new Exception(ResponseHelper.exceptionMessage(response));

        return await Radzen.HttpResponseMessageExtensions.ReadAsync<Radzen.ODataServiceResult<LunaAba.Server.Models.Consulta.ProfissionaisView>>(response);

Any feedback on this yet? I have just encountered the same issue using code built by Blazor Studio.

No feedback yet. To make it work i had to change the return type in the client to IEnumerable. But this way i have to make another call to the same endpoint without the pagination to get the total records count.

A customer reported a similar problem related to the following code being removed after database infer:

services.AddControllers().AddOData(opt =>

We have not been able to reproduce this issue so far and would need some code that shows the issue. You can send your app to and a SQL CREATE script of your database. To reduce the size delete any bin or obj directories. Otherwise use a cloud storage service such as Dropbox, OneDrive, GoogleDrive or similar.

I’m the Customer that had this same problem. For me it was that the OData Controller service reference in the Startup.cs in my case. It did not get recreated when I re-inferred from the database. Make sure all you tables show there.

@Crowmmark is correct in identifying that the root cause was the OData routing in startup.cs( or progam.cs in my case).

Message: The requested operation requires an element of type 'Object', but the target element has type 'Array'.

The error indicates that we are just returning the data without the OData attributes caused by the route not being identified as an OData route.

I have seen issues with the OData routes when inferring the database multiple times to capture changes but it is easily resolved by cleaning up the startup/program. However, in my case, I had caused the issue myself by mistyping a new route.

My issue was caused because I had code commented out right before that line. I removed it and it now infers properly.

In my case the other methods of the same controller works well. The problem is only with this custom method. The code in program.cs seems Ok.