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

Incorrect parameter ordering for CancellationToken in generated RequestBuilder code #4692

Closed
johnholliday opened this issue May 21, 2024 · 5 comments · Fixed by #4700
Closed
Assignees
Labels
Csharp Pull requests that update .net code type:bug A broken experience
Milestone

Comments

@johnholliday
Copy link

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Windows executable

Client library/SDK language

Csharp

Describe the bug

The generated API client code fails to compile with the following error:

Argument 3: cannot convert from 'System.Threading.CancellationToken' 
to 'System.Collections.Generic.Dictionary<string, 
Microsoft.Kiota.Abstractions.Serialization.ParsableFactory
<Microsoft.Kiota.Abstractions.Serialization.IParsable>>?'

Expected behavior

The generated code should compile without errors. Specifically, the 'cancellationToken' parameter should be preceded by 'null', as in:

var requestInfo = ToDeleteRequestInformation(requestConfiguration);
return await RequestAdapter.SendAsync<UntypedNode>(requestInfo, default, **null**, cancellationToken).ConfigureAwait(false);

How to reproduce

  1. Create a new .NET class library project.
  2. Generate the C# Api client.
  3. Compile the project.

Open API description file

No response

Kiota Version

1.14.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

Manually edit the generated code.

Configuration

Windows 11 x64

Debug output

Click to expand log ```
</details>


### Other information

_No response_
@johnholliday johnholliday added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels May 21, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota May 21, 2024
@andrueastman
Copy link
Member

Thanks for raising this @johnholliday

Is this occurring on all methods or just a specific generated method? Are you able to share a sample of the description that replicates this scenario?

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels May 21, 2024
@andrueastman andrueastman moved this from Needs Triage 🔍 to Todo 📃 in Kiota May 21, 2024
@andrueastman andrueastman added this to the Backlog milestone May 21, 2024
@johnholliday
Copy link
Author

@andrueastman Only on DeleteAsync and GetAsync. Sample project attached.
Kiota.Test.zip

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels May 21, 2024
@andrueastman andrueastman self-assigned this May 22, 2024
@andrueastman andrueastman added the Csharp Pull requests that update .net code label May 22, 2024
@andrueastman
Copy link
Member

Authored #4700 to resolve

@andrueastman andrueastman moved this from Todo 📃 to In Progress 🚧 in Kiota May 22, 2024
@baywet baywet modified the milestones: Backlog, Kiota v1.15 May 22, 2024
@github-project-automation github-project-automation bot moved this from In Progress 🚧 to Done ✔️ in Kiota May 22, 2024
@johnholliday
Copy link
Author

Authored #4700 to resolve

There is still a minor problem that causes CS8625 warnings on code like the following:

#nullable enable
        public async Task<UntypedNode?> DeleteAsync(Action<RequestConfiguration<DefaultQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
        {
#nullable restore
#else
        public async Task<UntypedNode> DeleteAsync(Action<RequestConfiguration<DefaultQueryParameters>> requestConfiguration = default, CancellationToken cancellationToken = default)
        {
#endif
            var requestInfo = ToDeleteRequestInformation(requestConfiguration);
            return await RequestAdapter.SendAsync<UntypedNode>(requestInfo, /* CS8625 ==> */default, null, cancellationToken).ConfigureAwait(false);
        }

warning CS8625: Cannot convert null literal to non-nullable reference type

Without delving further to determine if this manual fixup causes other issues, the warning goes away when patched as follows:

return await RequestAdapter.SendAsync<UntypedNode>(requestInfo, default!, null, cancellationToken).ConfigureAwait(false);

However, in my opinion, the generated code should compile without warnings and should not require manual fixups.

@andrueastman
Copy link
Member

Thanks for the feedback @johnholliday

following up via #4727

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code type:bug A broken experience
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants