Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0411 

Error Message

The type arguments for method 'method' cannot be inferred from the usage. Try specifying the type arguments explicitly.

This error occurs if you call a generic method without explicitly providing the type arguments and the compiler cannot infer which type arguments are intended. To avoid this error, add the intended type arguments in angle brackets.

Example

The following sample generates CS0411:

// CS0411.cs
class C
{
    void G<T>()
    {
    }

    public static void Main()
    {
        G();  // CS0411
        // Try this instead:
        // G<int>();
    }
}

Other possible error cases include when the parameter is null, which has no type information:

// CS0411b.cs
class C
{
    public void F<T>(T t) where T : C 
    {
    }

    public static void Main()
    {
        C c = new C();
        c.F(null);  // CS0411
    }
}

Another case occurs when a conversion is involved on one of multiple parameters:

// CS0411c.cs

class C
{
    void F<T>(T t1, T t2)
    {
    }

    public static void Main()
    {
        C c = new C();
        c.F(1, 2L);  // CS0411 -- is T int or long?
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft