Compiler Warning (level 1) CS1956

Member 'name' implements interface member 'name' in type 'type'. There are multiple matches for the interface member at run-time. It is implementation dependent which method will be called.

This warning can be generated when two interface methods are differentiated only by whether a particular parameter is marked with ref or with out. It is best to change your code to avoid this warning because it is not obvious or guaranteed which method is called at run time.

Although C# distinguishes between out and ref, the CLR sees them as the same. When deciding which method implements the interface, the CLR just picks one.

To avoid this warning

  1. Give the compiler some way to differentiate the methods. For example, you can give them different names or provide an additional parameter on one of them.

Example

The following code generates CS1956 because the two Test methods in Base differ only by the ref/out modifier on the first parameter.

// cs1956.cs  
class Base<T, S>  
{  
    // This is the method that should be called.  
    public virtual int Test(out T x) // CS1956  
    {  
        x = default(T);  
        return 0;  
    }  
  
    // This is the "last" method and is the one that ends up being called  
    public virtual int Test(ref S x)  
    {  
        return 1;  
    }  
}  
  
interface IFace  
{  
    int Test(out int x);  
}  
  
class Derived : Base<int, int>, IFace  
{  
    static int Main()  
    {  
        IFace x = new Derived();  
        int y;  
        return x.Test(out y);  
    }  
}