Skip to content

JsonDocument problem when using [UseProjection] #5893

@alandecastros

Description

@alandecastros

Is there an existing issue for this?

  • I have searched the existing issues

Product

Hot Chocolate

Describe the bug

I've tested on the latest version of HotChocolate (13.0.5).
The JsonDocument works fine if I don't use the UseProjection attribute. IF I use it I get the following error:

{
  "errors": [
    {
      "message": "Unexpected Execution Error",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "testes"
      ],
      "extensions": {
        "message": "Type 'System.Text.Json.JsonDocument' does not have a default constructor (Parameter 'type')",
        "stackTrace": "   at System.Linq.Expressions.Expression.New(Type type)\r\n   at HotChocolate.Data.Projections.Expressions.QueryableProjectionScopeExtensions.CreateMemberInit(QueryableProjectionScope scope)\r\n   at HotChocolate.Data.Projections.Expressions.Handlers.QueryableProjectionFieldHandler.TryHandleLeave(QueryableProjectionContext context, ISelection selection, ISelectionVisitorAction& action)\r\n   at HotChocolate.Data.Projections.ProjectionVisitor`1.Leave(ISelection selection, TContext context)\r\n   at HotChocolate.Data.Projections.SelectionVisitor`1.Visit(ISelection selection, TContext context)\r\n   at HotChocolate.Data.Projections.SelectionVisitor`1.VisitObjectType(IOutputField field, ObjectType objectType, ISelection selection, TContext context)\r\n   at HotChocolate.Data.Projections.Expressions.QueryableProjectionVisitor.VisitObjectType(IOutputField field, ObjectType objectType, ISelection selection, QueryableProjectionContext context)\r\n   at HotChocolate.Data.Projections.SelectionVisitor`1.VisitChildren(IOutputField field, TContext context)\r\n   at HotChocolate.Data.Projections.SelectionVisitor`1.Visit(IOutputField field, TContext context)\r\n   at HotChocolate.Data.Projections.ProjectionVisitor`1.Visit(IOutputField field, TContext context)\r\n   at HotChocolate.Data.Projections.ProjectionVisitor`1.Visit(TContext context, ISelection selection)\r\n   at HotChocolate.Data.Projections.Expressions.QueryableProjectionProvider.<CreateApplicator>b__7_0[TEntityType](IResolverContext context, Object input)\r\n   at HotChocolate.Data.Projections.Expressions.QueryableProjectionProvider.<>c__DisplayClass4_0`1.<<CreateExecutor>g__ExecuteAsync|1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.Data.ToListMiddleware`1.InvokeAsync(IMiddlewareContext context)\r\n   at HotChocolate.Resolvers.Expressions.Parameters.ServiceHelper.<>c__DisplayClass7_3`1.<<UseResolverServiceInternal>b__5>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.Resolvers.Expressions.Parameters.ServiceHelper.<>c__DisplayClass7_1`1.<<UseResolverServiceInternal>b__3>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
      }
    }
  ]
}

Steps to reproduce

https://github.com/glen-84/hc-5893 (.NET 8, HC 13.8.1)

  1. Create a query using [UseProjection]
  2. The model that is returned must have a JsonDocument attribute

Relevant log output

No response

Additional Context?

No response

Version

13.0.5

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions