How to control which .NET assembly chooses a namespace conflict?

I need (to carry with me) for one reason or another to use the version of the System.Text.Encoding namespace in WinRT. I can add the assembly reference manually and so, but it will still use the mscorlib implementation. And I can not completely remove mscorlib.

How can I make my project use WinRT System.Text.Encoding.dll instead of mscorlib?

Basically, I need it to generate this IL fragment:

call class [System.Text.Encoding]System.Text.Encoding [System.Text.Encoding]System.Text.Encoding::get_UTF8() 

instead of this:

 call class [mscorlib]System.Text.Encoding [mscorlib]System.Text.Encoding::get_UTF8() 
+4
source share
1 answer

You need to specify a link. To do this, go to Solution Explorer and select the link for which you want to use an alias. View the properties and edit the Aliases field to add a unique alias name.

Alias โ€‹โ€‹field in properties with custom alias, myalias

Once you have defined a unique alias, you will edit your code to add an extern alias declaration.

 extern alias myalias; 

Finally, you refer to types through an alias, as in (this example is aliased System.dll):

 myalias::System.Diagnostics.Trace.WriteLine("I referenced this via my alias."); 

Now this points to the desired link, even if other links also provide a type with the same name and namespace.

For more information about aliases, see fooobar.com/questions/98068 / ... on What is the use of the assembly link alias property .

+6
source

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


All Articles