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
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.
Comments