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

[BUG]: CS0854 Compiler Error When Using Optional Arguments in Expression Trees #331

Open
1 task done
cilerler opened this issue Dec 15, 2024 · 2 comments
Open
1 task done
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented

Comments

@cilerler
Copy link

What happened?

In the example below, the call to ProjectsV2(first: 10) inside the Select lambda results in this compiler error:

CS0854 - An expression tree may not contain a call or invocation that uses optional arguments.

It would be helpful to provide clearer guidance or workarounds.

var query = new Query()
                .Repository(owner: owner, name: repo)
                .Issue(number: issueNumber)
                .Select(i => new
		                {
			          i.Id,
			          i.Title,
			          i.Number,
			          Projects = i.ProjectsV2(first: 10).Nodes        // <=== CS0854
			            .Select(p => new
			              {
				              p.Number,
				              p.Title
			              })
		                });

Versions

Nuget: Octokit.GraphQL 0.40.0-beta

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@cilerler cilerler added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Dec 15, 2024
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@nickfloyd nickfloyd moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Dec 23, 2024
@cilerler
Copy link
Author

cilerler commented Jan 4, 2025

I came across this note in the Octokit GraphQL .NET documentation:

You can see a bunch of null parameters in the r.Issues() call. This is because expressions in C# do not support default parameter values, so all the unused values need to be supplied an explicit null. It sucks.

Based on this explanation, I updated my query from

Projects = i.ProjectsV2(first: 10).Nodes

to

Projects = i.ProjectsV2(10, null, null, null, null, null).Nodes

and it worked.

Leaving this workaround here in case someone else encounters the same issue.

However, I’m keeping this issue open because it highlights a need for refactoring and improved implementation/documentation to handle such cases more gracefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

1 participant