Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Type XX exists in both DLLs

I am developing a silverlight C# app, and I have added a reference to a Microsoft DLL and got the following message:

The type exists in both DLLs

Since I am using a control that is defined in both of the DLLs (one is associated with the SDK, the other one I added myself).

After did some research on the internet, I tried to make an alias of both of DLLs, and import them by using extern alias <alias_name>. This approach solved some problem in the xaml.cs code behind, but did not really solve the problem in xaml. After I did this, Visual Studio complained that one of the controls (from the DLL I added) is not defined in the namespace.

So I am wondering if there is a way to specify namespace in XML using an alias?

Thank you.

like image 920
Allan Jiang Avatar asked Aug 01 '12 16:08

Allan Jiang


2 Answers

Stackoverflow

MSDN

You just need to add a second alias to your assembly using comma delimiters.

eg

<Aliases>global,alias_name</Aliases>

XAML will use the global alias, and you can pick and choose in your classes.

.

If you need to use both assemblies in one place, I think this solution is the only one.

Basically, create two wrapper classes in separate namespaces in your own project for each required class, then reference the wrapper namespaces instead of the conflicting assemblies.

like image 120
Silver Solver Avatar answered Oct 13 '22 05:10

Silver Solver


There is a good way if you use class from duplicated namespae in C# code (not in XAML) http://csc-technicalnotes.blogspot.ru/2009/07/type-exists-in-both-dlls.html

Use an external assembly alias. 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".

Specify alias in C# source code:

// Old way
using MyNamespace;

// New way
extern alias LegacyMyDLL;
using LegacyMyDLL.MyNamespace;
like image 43
Alexander Avatar answered Oct 13 '22 04:10

Alexander