Can two classes with the same name be in the same namespace across two different assemblies?

pavuxun

I have two different assemblies: Assembly1 and Assembly2. Both assemblies use the same namespace SoftwareDrivers. Now, I have two implementations of a class that has identical functionality, just different implementation and dependencies that tie one implementation to Assembly1 and the other to Assembly2; I'll call this class PackageWriter.

It is possibly, and likely, some projects will need to reference both assemblies, so I anticipate there will be an issue with resolving which PackageWriter to use in that scenario. Is this the case? If so, is the only way to resolve this issue, without changing the structure of the project, to change the name of PackageWriter?c

TheSoftwareJedi

Yes they can. If both assemblies are referenced, you will receive an error similar to this:

error CS0433: The type 'Testing' exists in both 'MyApp.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'MyApp.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

Note, you should never purposefully put yourself in this situation. However, if you for some reason find yourself in a situation where you have to handle this:

Every assembly has an "alias" in .NET and by default it is global. This is usually invisible to the day to day programmer. You can change the alias by clicking on the reference and changing the Alias in Properties. You would then reference it by having extern alias myalias at the top of your file, and the actual class referenced like this myalias::MyApp.Testing

This is perhaps needed when running 2 versions of an API or similar, although I maintain to avoid this if at all possible.

For more detail, see this answer.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java Namespace - Two classes with the same name in different packages

From Dev

Two assemblies with same name ,same version but different public key

From Dev

Two assemblies with same name ,same version but different public key

From Dev

Two classes with the name in the same module with different bases?

From Dev

How can I load two versions of same assemblies into two different domains from two different subfolders?

From Dev

How can I load two versions of same assemblies into two different domains from two different subfolders?

From Dev

Can two different classes inherit same base?

From Dev

How does CLR differentiate classes with the same name but without namespace in different assemblies at runtime?

From Dev

Java - Two classes, same name, same package but in different folders

From Java

Can you have two classes with the same name and the same member function in different translation units?

From Dev

Instantiate different classes with the same name/namespace

From Dev

two classes, same property name, different type -> gets overridden

From Dev

Java Templates, how to use two classes with the same name and different types

From Dev

The same type is defined in two assemblies

From Dev

Can I define a common interface for two classes with same property name?

From Dev

Can two html elements have the same id but in different classes?

From Dev

Are two classes in same namespace & project also in the same executing assembly?

From Dev

for loop calling two different files (same name, different extension) across several files

From Dev

In QT, can we have two slots with same name but different arguments?

From Dev

Can two application have the same Bundle Name, but different Bundle Identifier?

From Dev

Can I have two users with the same name but different UID's?

From Dev

How can two files with same name, content, owner, and permissions be different?

From Dev

How to distinguish between two classes with the same name (and namespace) in 2 DLL's?

From Java

Import two exported classes with the same name

From Dev

Java - Using two classes with the same name in an Interface

From Dev

How to give two different classes the same interface?

From Dev

Hibernate: mapping same column for two different classes

From Dev

Swift - Same protocol for two different classes

From Dev

How to give two different classes the same interface?

Related Related

  1. 1

    Java Namespace - Two classes with the same name in different packages

  2. 2

    Two assemblies with same name ,same version but different public key

  3. 3

    Two assemblies with same name ,same version but different public key

  4. 4

    Two classes with the name in the same module with different bases?

  5. 5

    How can I load two versions of same assemblies into two different domains from two different subfolders?

  6. 6

    How can I load two versions of same assemblies into two different domains from two different subfolders?

  7. 7

    Can two different classes inherit same base?

  8. 8

    How does CLR differentiate classes with the same name but without namespace in different assemblies at runtime?

  9. 9

    Java - Two classes, same name, same package but in different folders

  10. 10

    Can you have two classes with the same name and the same member function in different translation units?

  11. 11

    Instantiate different classes with the same name/namespace

  12. 12

    two classes, same property name, different type -> gets overridden

  13. 13

    Java Templates, how to use two classes with the same name and different types

  14. 14

    The same type is defined in two assemblies

  15. 15

    Can I define a common interface for two classes with same property name?

  16. 16

    Can two html elements have the same id but in different classes?

  17. 17

    Are two classes in same namespace & project also in the same executing assembly?

  18. 18

    for loop calling two different files (same name, different extension) across several files

  19. 19

    In QT, can we have two slots with same name but different arguments?

  20. 20

    Can two application have the same Bundle Name, but different Bundle Identifier?

  21. 21

    Can I have two users with the same name but different UID's?

  22. 22

    How can two files with same name, content, owner, and permissions be different?

  23. 23

    How to distinguish between two classes with the same name (and namespace) in 2 DLL's?

  24. 24

    Import two exported classes with the same name

  25. 25

    Java - Using two classes with the same name in an Interface

  26. 26

    How to give two different classes the same interface?

  27. 27

    Hibernate: mapping same column for two different classes

  28. 28

    Swift - Same protocol for two different classes

  29. 29

    How to give two different classes the same interface?

HotTag

Archive