Predefined type ‘System.Runtime.CompilerServices.IsExternalInit’ is not defined or imported [duplicate]

This is a small bug in Visual Studio 2019 that hasn’t been fixed yet. To solve this, you need to add a dummy class named IsExternalInit with the namespace System.Runtime.CompilerServices anywhere in your project. That will do it.

If writing a library it’s best to make this class internal, as otherwise you can end up with two libraries both defining the same type.

    namespace System.Runtime.CompilerServices
    {
          internal static class IsExternalInit {}
    }

Edit (November 16, 2020):

According to a reply I got from the Principle Developer Lead on C# Language Team, Jared Parsons, the issue above is not a bug. The compiler throws this error because we’re compiling a .NET 5 code against older .NET Framework version. See his message below:

Thanks for taking the time to file this feedback issue. Unfortunately
this is not a bug. The IsExternalInit type is only included in the
net5.0 (and future) target frameworks. When compiling against older
target frameworks you will need to manually define this type.

Link to the report on Visual Studio Developer Community: https://developercommunity.visualstudio.com/content/problem/1244809/error-cs0518-predefined-type-systemruntimecompiler.html

Leave a Comment