Suresh Rajput
Suresh Rajput

Reputation: 39

Error while accessing class which is present in two different assemblies

I have one project which has a reference of two different dlls. When I'm creating object of that class it says below error

Severity Code Description Project File Line Suppression State Error CS0433 The type 'clsRMQNew' exists in both 'XXXX.abc.System, Version=11.0.0.3, Culture=neutral, PublicKeyToken=null' and 'YYYY.Common.Queue, Version=16.12.26.1, Culture=neutral,

Please guide me how do i access that class from either of one assembly. Is there any solution for the same ?

Upvotes: 2

Views: 84

Answers (3)

Steve
Steve

Reputation: 216293

The compiler complains with you because you have declared somewhere a variable in this way

clsRMQNew rmq = new clsRMQNew();

But it is impossible, for the compiler, to know which assembly should be used to create your variable because there are two assemblies with the same name and you haven't given any hint on which assembly to use.
Thus it stops the compilation with the error mentioned

You can fix this problem adding the whole qualified name of the class

XXXX.abc.System.clsRMQNew rmq = new XXXX.abc.System.clsRMQNew();

or

YYYY.Common.Queue.clsRMQNew rmq = new YYYY.Common.Queue.clsRMQNew();

depending on which class you want to use.

You can also shorten these declarations adding this to your using directives

using QueueA = YYYY.Common.Queue;

and then

QueueA.clsRMQNew rmq = new QueueA.clsRMQNew();

Upvotes: 1

Kitson88
Kitson88

Reputation: 2940

You need to prefix the class (Fully Qualify) with the specific namespace you intend to use to avoid conflicts.

using NameSpaceOne;
using NameSpaceTwo;

namespace StackOverflow
{
    class Program
    {
        static void Main(string[] args)
        {

            var dupObjectOne = new NameSpaceOne.DuplicateClass() { value = 1};
            var dupObjectTwo = new NameSpaceOne.DuplicateClass() { value = 2 };
        }
    }
}

namespace NameSpaceOne
{
    class DuplicateClass
    {
        public int value { get; set; }
    }
}

namespace NameSpaceTwo
{
    class DuplicateClass
    {
        public int value { get; set; }
    }
}

Upvotes: 1

nvoigt
nvoigt

Reputation: 77304

You will need to provide the full name of the class:

var one = new XXXX.abc.System.clsRMQNew();
var two = new YYYY.Common.Queue.clsRMQNew();

Upvotes: 0

Related Questions