A personal repository of technical notes. - CSC

Type Exists in Both DLLs

Problem
Have two versions of a DLL that use the same namespaces and class names.

Project compliation throws the following error:

The type 'MyNamespace.MyClass' exists in both 'MyDLLv1.dll' and 'MyDLLv2.dll'
error CS0433: The type 'MyNamespace.MyClass' exists in both 'MyDLLv1.dll' and 'MyDLLv2.dll'


Solution
Use an external assembly alias.
  1. Specify "Aliases" property of DLL reference.
    1. In Visual Studio Solution Explorer, open References folder.
    2. Right-click DLL reference, select Properties
    3. Enter alias value in "Aliases" property.
    4. Example: Alias to MyDLLv1.dll reference could be "LegacyMyDLL".
  2. Specify alias in C# source code:

// Old way

using MyNamespace;

// New way

extern alias LegacyMyDLL;

using LegacyMyDLL.MyNamespace;

Microsoft References
Note: Could find no Microsoft references for specifying "Aliases" property of DLL reference within Visual Studio. Only for specifying compilation command line parameter.

"/reference (Import Metadata) (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 22 July 2009 http://msdn.microsoft.com/en-us/library/yabyz3h4(VS.80).aspx.

"Extern alias (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 22 July 2009 http://msdn.microsoft.com/en-us/library/ms173212(VS.80).aspx.

"How to: Use the Namespace Alias Qualifier (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 22 July 2009 http://msdn.microsoft.com/en-us/library/c3ay4x3d(VS.80).aspx.

Other References
"What use is the Aliases property of assembly references in Visual Studio 8. -." Stack Overflow. 22 July 2009 http://stackoverflow.com/questions/286632/what-use-is-the-aliases-property-of-assembly-references-in-visual-studio-8.

"Enhancements in Assemblies and Versioning in Visual Studio 2005." C#, Visual Studio 2008, Silverlight, ASP.NET, WPF, WCF, WF, and Windows Vista Community. 22 July 2009 http://www.c-sharpcorner.com/UploadFile/rambab/Assembly04292006002740AM/Assembly.aspx?ArticleID=69edb807-8118-4933-8366-773e87ee80ad.

1 comment:

cheap erectile dysfunction pills online said...

Greetings from Colorado! I'm bored at work so I decided to check out your website on my iphone during lunch break. I love the knowledge you present here and can't wait to take a look when I get home. I'm shocked at how quick your blog loaded on my mobile .. I'm not even using WIFI, just 3G .. Anyhow, good site!

Post a Comment