How to Resolve Error "CS0682: 'MyClass' cannot implement 'IExternalInterface' because it is not supported by the language" in C#
The Compiler Error CS0682 is an interoperability error. The message reads: "'MyClass' cannot implement 'IExternalInterface' because it is not supported by the language".
The .NET Common Language Runtime (CLR) is a powerful platform that supports many languages (C#, VB.NET, F#, C++/CLI). The CLR itself supports features that are valid in the compiled bytecode (IL) but do not exist in the C# language specification.
This error occurs when you attempt to implement an interface or inherit from a class defined in another language (usually C++/CLI or older VB.NET) that contains a member C# does not know how to express syntactically. Common culprits include Named Indexed Properties (properties with arguments that are not the default indexer) or methods using unsupported calling conventions.
Understanding the CLR vs. C# Gap
While C# is the primary language of .NET, it does not support every single feature the underlying runtime offers.
- C# Restriction: You can have only one indexer per class, accessed via
this[...]. - CLR Capability: You can have multiple properties that take arguments (e.g.,
obj.Props["key"],obj.Values[0]). This is supported in VB.NET.
If you reference a DLL created in VB.NET or C++ that defines an interface with a Named Indexed Property, C# physically cannot write the syntax required to implement that interface. The compiler sees the contract, realizes it requires a feature C# lacks, and raises CS0682.
Scenario: The Named Indexed Property
Imagine you are referencing a legacy library (LegacyLib.dll) written in VB.NET or C++/CLI.
The External Interface (Pseudo-code of the DLL content):
// Defined in a different language (e.g., VB.NET)
public interface IComplexData
{
// A property named 'Values' that takes an index.
// C# ONLY allows 'this[int index]', not 'Values[int index]'.
string Values(int index) { get; set; }
}
Your C# Code:
using LegacyLib;
// ⛔️ Error CS0682: 'MyWrapper' cannot implement 'IComplexData'
// because it is not supported by the language.
public class MyWrapper : IComplexData
{
// There is no syntax in C# to implement 'Values(int index)'.
// We can write 'public string this[int i]', but that maps to 'Item', not 'Values'.
}
The C# compiler is stuck. It must fulfill the contract of IComplexData, but it has no grammar to define the implementation.
Solution 1: Composition Instead of Inheritance
If you cannot implement the interface, you likely shouldn't be trying to inherit from it directly. Instead, use Composition. Hold a reference to an object that implements the interface (provided by the library) rather than trying to be that object.
If you absolutely need to pass your object to a method expecting IComplexData, this solution won't work directly, but usually, these interfaces are meant to be consumed, not implemented.
public class MyWrapper
{
private IComplexData _externalData;
public MyWrapper(IComplexData data)
{
_externalData = data;
}
public string GetValue(int index)
{
// ✅ Correct: C# CAN CALL these members (using get_Values),
// it just cannot IMPLEMENT them.
return _externalData.get_Values(index);
}
}
Solution 2: Create a Bridge (Adapter Pattern)
If you strictly must implement the interface (e.g., to pass a callback object to an external API), you need a language that supports the feature to act as a bridge.
- Create a C++/CLI or VB.NET project in your solution.
- Implement the interface in that project (since those languages support named indexers).
- Inherit from that intermediate class in C#.
Step 1 (VB.NET Helper Class):
' In a VB.NET Class Library
Public Class Bridge
Implements LegacyLib.IComplexData
' Implement the problematic member here
Public Property Values(index As Integer) As String Implements IComplexData.Values
Get
Return OnGetValues(index)
End Get
Set(value As String)
OnSetValues(index, value)
End Set
End Property
' Expose standard methods for C# to override
Protected Overridable Function OnGetValues(index As Integer) As String
Return String.Empty
End Function
Protected Overridable Sub OnSetValues(index As Integer, value As String)
End Sub
End Class
Step 2 (C# Implementation):
// Now you inherit from the Bridge class, overriding the C#-friendly methods
public class MyCsharpClass : Bridge
{
// ✅ Correct: We are implementing logic for the interface
// via the friendly hooks provided by the VB.NET bridge.
protected override string OnGetValues(int index)
{
return $"Value at {index}";
}
}
Conclusion
CS0682 is a hard limit of the C# language syntax.
- Identify the Member: Look at the interface definition in the Object Browser. Look for properties with arguments that aren't the default indexer (
Item). - Avoid Implementation: Usually, you are supposed to consume these libraries, not extend them. Check if you can use Composition.
- Bridge It: If implementation is mandatory, write a small wrapper in VB.NET or C++/CLI to bridge the gap between the CLR features and C#.