Type XX exists in both DLLs

I am developing a Silverlight C # application and I added a link to the Microsoft DLL and received the following message:

Type exists in both DLLs.

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

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

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

Thanks.

+6
source share
2 answers

fooobar.com/questions/921864 / ...

MSDN

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

eg

 <Aliases>global,alias_name</Aliases> 

XAML will use a global alias, and you can select and select 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 class you want, and then reference shell namespaces rather than conflicting assemblies.

+4
source

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

Use an external assembly alias. Specify the "Aliases" property of the DLL link.

  • In the Visual Studio Solution Explorer, open the Links folder.
  • Right-click the link for the DLL, select "Properties"
  • Enter a value for the alias in the Aliases property.
  • Example: Alias ​​reference to MyDLLv1.dll may be "LegacyMyDLL".

Specify an alias in the C # source code:

 // Old way using MyNamespace; // New way extern alias LegacyMyDLL; using LegacyMyDLL.MyNamespace; 
+2
source

Source: https://habr.com/ru/post/921862/


All Articles