简体   繁体   中英

Same class name and assembly name in .net

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 eg

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

MyComponent varCom;

But I want to include an assembly which has a same name as my class ie 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

PS The error is "'MyComponent' is a 'namespace' but is used like a 'type'"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM