Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top