✅ IsExternalInit Issue Not Found and Duplicate
Hi all, I'm working in a project that multi-targets net461, net461, net6.0, and net7.0. On the net461 target, I'm encountering an error stating "Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported." The
IsExternalInit
nuget package is installed.
StackOverflow suggested that I can create a custom internal class like so:
Adding this class does not get rid of the error, but it does add a new error saying "The namespace 'System.Runtime.CompilerServices.' already contains a definition for 'IsExternalInit'." So it both can't find it and reports a duplicate at the same time. Restarting Visual Studio and deleting obj, bin, and output folders does not resolve the issue.
Any ideas of what might be going on here?11 Replies
Ok strange.
Of all the things, opening the erroring files resolved the error. Not sure how that's different than clearing the obj, bin, and output folders and rebuilding, because it was throwing the error on build, but that resolved it.
you mention
net461
twice in your post, so not sure if something is missing there. but i'd suggest maybe wrapping that in a #if !NET6_0_OR_GREATER
maybe NET5_0_OR_GREATER
even, since that's when it was introduced (even if you don't target it)What Ero said. Alternatively you can support this in your project: https://github.com/Sergio0694/PolySharp
Adding this will automatically support the feature in .NET versions before .NET 5
Don't ask me how it works
poly sharsh a source generator
Oh this is nice
✨magic✨
Yeah but the thing tha goes over my head is how exactly source generating small ass attributes is going to support newer syntactic sugar
I guess the compiler works like that
Would PolySharp replace my IsExternalInit nuget include?
Yes
It also supports that
that should be gone anyway imo
Got it
just have a
Polyfill
folder if you do it manually
i find it nicer to be in control of what i fill