✅ (solved!) "System.InvalidOperationException: Sequence contains no elements" error from Roslyn
Hi guys! I'm trying to publish my C# project using
dotnet publish -c Debug --nologo -r win-x64
, but I'm getting a cryptic error message, which I've attached to this post. (<MSBuild> refers to C:\Program Files\dotnet\sdk\<version>\Roslyn\Microsoft.CSharp.Core.targets
)
I have no idea how to fix this, to be honest - I've looked this up on Google but to no avail. I'm using shared projects, so maybe that's causing some issues...?28 Replies
Here's the full log:
Looks like a Roslyn bug?
that's what i hope is not the case... i'm looking at the
-v diag
output right now, but that doesn't really give me any clues on what's happening
if that is a roslyn bug, a repro case would be extremely difficult to create because i don't even know what causes it xdYou can try asking in #roslyn since someone there might have more insight regarding the stack trace
this is what it spits out right before crashing
alright, i'll send a link to the thread there
This should be a Roslyn bug. You need to open an issue at dotnet/roslyn repository, and it would be great if you can upload a repro project to the issue
i identified what line caused the error
after removing this specific line, the error disappears (more appear, but they're unrelated)
but that's such a random line for it to fail on...
alright i have no idea why removing that one line does anything, i tried putting what crashes in my solution into a new one and it compiles fine
what's the type of
value1
? Are you able to share the project which the compiler is crashing on?i'm working on a repro project right now, it really does seem that line causes the issue since i'm able to get it to get to the linking stage (which ofc is dependent on roslyn working)
value1
is T
(it's a generic method)
alright oddly enough now when i uncomment it now it works correctly??version of the compiler in use? (can determine by adding
#error version
to your code)Compiler version: '4.4.0-6.22608.27 (af1e46ad)
I think the crash is going through this path https://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/Lowering/LocalRewriter/LocalRewriter_ConditionalAccess.cs,136
oh yep i fixed link errors and im getting that error again
maybe it's something to do with shared projects...? they are very buggy in my experience
i did
and VS does not play well with that
but if i don't do that, then it wants to add an entry to the projitems for every file deleted/added, which is very prone to merge conflicts
I think this is saying: the type of the
a?.b
expression is a Nullable, so we essentially want to make an expression like new int?(a.b)
, and for some reason, we found no constructor on int?
with a single parameter.
Is there any chance your project is referencing a bogus definition of System.Nullable?oh, yeah! i don't have a single param constructor there
lemme implement one real quick
Is this a polyfill or something?
yyyyep, seems to be it...
nope
D:
i'm implementing my own runtime
osdev with C#, very novel concept
Well! I'm glad I could help figure it out..
wow, that's cool
yeah, thanks for the help!!
It might be good if you could file a bug on us
If compiler needs to use a well-known member like this, we usually want it to report a binding-time error if the member doesn't exist
Not sure if bug will be prioritized 😉 but good to have a record of it.
what repo is best to file it under? dotnet/roslyn?
https://github.com/dotnet/roslyn/issues/67709 issue filed! (hope the maintainers aren't gonna laugh at me since this is such a specific issue lol)
GitHub
Missing Nullable(T) constructor triggers an LINQ empty sequence exc...
Version Used: 4.4.0-6.22608.27 (af1e46a) Steps to Reproduce: Create an MSBuild NativeAOT C# project, and set <NoStdLib> to true. Create a basic runtime implementation. The ZeroSharp no-runtim...
thanks! And don't worry about it. 🙂 These are bugs we would probably file on ourselves if we discovered them, even if we might not go out of our way to fix them.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.