Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendPrimitiveAsync throws InvalidOperationException for enums #274

Closed
MartinM85 opened this issue Jun 21, 2024 · 2 comments · Fixed by #291
Closed

SendPrimitiveAsync throws InvalidOperationException for enums #274

MartinM85 opened this issue Jun 21, 2024 · 2 comments · Fixed by #291
Assignees

Comments

@MartinM85
Copy link
Contributor

MartinM85 commented Jun 21, 2024

I've an endpoint which returns enum (C#):

return Ok(MyEnum.Value1);

The generated code for GetAsync looks like this:

return await RequestAdapter.SendPrimitiveAsync<MyEnum?>(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false);

But it throws InvalidOperationException with message error handling the response, unexpected type

I can't find any workaround for it right now

@MartinM85
Copy link
Contributor Author

@baywet Out of the scope of this issue, but if the server returns collection of enums, the generated client code is

return await RequestAdapter.SendPrimitiveCollectionAsync<MyEnum?>(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false);

SendPrimitiveCollectionAsync internally calls GetCollectionOfPrimitiveValues https://github.com/microsoft/kiota-serialization-json-dotnet/blob/main/src/JsonParseNode.cs#L310 and it doesn't handle enums.

IParseNode exposes GetCollectionOfEnumValues and GetEnumValue, but they have constraint for T limited to enum. ModelType doesn't have any constraint.

@andrueastman
Copy link
Member

Transferring issue as part of #238

@andrueastman andrueastman transferred this issue from microsoft/kiota-http-dotnet Jul 9, 2024
@github-project-automation github-project-automation bot moved this from In Progress 🚧 to Done ✔️ in Kiota Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
2 participants