how to resolve Duplicate namspaces in c#
I have 2 assemblies Combres
and log4net
Both assemblies contain the same log4net.Appender
namespace (internal code included) - I need to inherit log4net.Appender.AdoNetAp开发者_开发知识库pender
.
How do I accomplish this.
You can probably specify an alias for one of the namespaces, like this:
using MyNameSpace = log4net.Appender;
Then inherit MyNameSpace.AdoNetAppender
Fully qualify the type. For example if you are trying to inherit from this class:
class MyAppender : log4net.Appender.AdoNetAppender
If you are trying to use / create an instance of this class:
var appender = log4net.Appender.AdoNetAppender;
If Combres
and log4net
both contain a type AdoNetAppender
in the log4net.Appender
namespace then you are in more trouble (and someone made a mistake - namespaces are designed to avoid these sorts of conflicts).
If this does happen then you can use the assembly reference "Aliases" property to resolve the conflict as described in What use is the Aliases property of assembly references.
Take a look at the documentation for extern alias. It allows you to explicitly reference classes in your code even if they are in the same namespace and have the same name.
You might, for example, reference the log4net classes like so:
extern alias l4n;
//... further down
l4n::log4net.Appender.AdoNetAppender l4nAppender = null;
The "l4n" alias also has to be added to the property page for the DLL reference in Visual Studio.
I'm quite sure that Combres itself does not use the log4net.Appender
namespace but Combres.Loggers
namespace.
But Combres
(2.2.1) contains a reference to log4net
. If your application contains a reference to log4net
as well (possibly even in another location than the log4net assembly that is referenced by Combres), this could result in the error you described.
(Multiple log4net-assemblies are referenced and of course these all contain the log4net.Appender
)
精彩评论