Same class name and assembly name in .net

773 views Asked by At

I have a class MyComponent in my project which is being contained in another assembly(MyAssembly). This class is being used at many places in my project as parameter of various functions or variable type e.g.

private void MyMethod(MyComponent com)
{
  //Method Implementation
}

MyComponent varCom;

But I want to include an assembly which has a same name as my class i.e. MyComponent. Now whenever I include this assembly, wherever MyComponent is being used as it start showing error

"'MyComponent' is a 'namespace' but is used like a 'type'".

One way to resolve it would be to give the full path for the reference path at all the places for MyComponent variable as shown below.

MyAssembly1.MyComponent varCom;

but it would require lot of code changes which I dont want to do. Is there any other way out for this problem

P.S The error is "'MyComponent' is a 'namespace' but is used like a 'type'"

1

There are 1 answers

0
Alioza On

I think the simplest solution in your context would be renaming your MyComponent class by refactoring before you reference the other assembly. Right click the class name, Refactor, Rename. This should automatically update the class name everywhere it's used.

Or you could do the same for the MyComponent name space.