C# Error CS0104 – ‘reference’ is an ambiguous reference between ‘identifier’ and ‘identifier’

C# Compiler Error

CS0104 – ‘reference’ is an ambiguous reference between ‘identifier’ and ‘identifier’

Reason for the Error

You will receive this error when you are trying to access a class where the same name is available in multiple namespaces that are imported in to your class.

For example, let’s have a look at the below code snippet.

using NameSpace1;
using NameSpace2;
namespace NameSpace1
{
    public class Class1
    {
    }
}

namespace NameSpace2
{
    public class Class1
    {
    }
}

public class DeveloperPublish
{
    public static void Main()
    {
        Class1 obj = new Class1();

    }
}

In this program, we have an instance of Class1 created in the class “DeveloperPublish” and Class1 is present in both NameSpace1 and NameSpace2.

You will receive the below error when you compile the above code.

Error CS0104 ‘Class1’ is an ambiguous reference between ‘NameSpace1.Class1’ and ‘NameSpace2.Class1’ ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 21 Active

C# Error CS0104 – 'reference' is an ambiguous reference between 'identifier' and 'identifier'

Solution

To fix the error, use the full name of the class along with the namespace to avoid the conflict.

namespace NameSpace1
{
    public class Class1
    {
    }
}

namespace NameSpace2
{
    public class Class1
    {
    }
}

public class DeveloperPublish
{
    public static void Main()
    {
        NameSpace1.Class1 obj = new NameSpace1.Class1();

    }
}