Feature ‘default interface implementation’ is not available in C#
Today in this article, we will cover below aspects,
Issue Description
.NET/.NET Core build in MSBuild or Visual Studio gives below or similar format of the error.
Feature ‘default interface implementation’ is not available in C# 7.3. Please use language version 8.0 or greater.
Or
Target runtime doesn’t support default interface implementation.
Resolution
The issue is most visible in .NET/.NET Core framework using a C# language version without the support of target runtime or missing default target language version in the project.
Step 1
Install Target Runtime
Please make sure to install the target .NET or .NET Core framework. You’ll need to set the machine to run a minimum .NET Core 3.0 0r .NET 5 and C# 8.0.
The C# 8.0 compiler can be made available by installing either of below,
- Visual Studio 2019 version 16.3 or
- .NET Core 3.0 or .NET 5 or above
If .NET Core 3.0 or .NET 5 is missing, you shall get an error like “Target runtime doesn’t support default interface implementation.”
Step 2
Target C# 8.0 language Version
This will be the second step for enabling C# 8.0 version on your local machine or build server.
C# compiler determines the language version (default) based on the project’s target framework.
If using .NET or .NET Core then this framework will always target only a single framework and which will also be a default version.
If you find the default version other than 8.0, then you can use any of the below techniques to target the specified version.
Please use the below command to verify the c# language version.
CSC /language:?
The language version can be targeted for 8.0 using any of the below techniques.
Edit Project File for 8.0
Please explicitly instruct the compiler that you would like to use the specific version of the language if the default setting doesn’t support it.
Note: For any issue please make sure to unload and re-load the Project in Visual Studio. You can even close and re-open the project for settings to be effective.
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
A similar setting can be applied at the build machine/server as needed. I have talked about multiple approaches in the below article,
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.