C
C#2y ago
Foxtrek_64

✅ 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:
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit {}
}
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit {}
}
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
Foxtrek_64
Foxtrek_64OP2y ago
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.
ero
ero2y ago
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)
FusedQyou
FusedQyou2y ago
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
ero
ero2y ago
poly sharsh peepoHappy a source generator
Foxtrek_64
Foxtrek_64OP2y ago
Oh this is nice ✨magic✨
FusedQyou
FusedQyou2y ago
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
Foxtrek_64
Foxtrek_64OP2y ago
Would PolySharp replace my IsExternalInit nuget include?
FusedQyou
FusedQyou2y ago
Yes It also supports that
ero
ero2y ago
that should be gone anyway imo
Foxtrek_64
Foxtrek_64OP2y ago
Got it
ero
ero2y ago
just have a Polyfill folder if you do it manually i find it nicer to be in control of what i fill

Did you find this page helpful?