error CS0433 for 'System.Windows.Automation' type

vsissu2e

Few days ago I had a strange issue in one of my Visual Studio 2013 solution. The Test project required functionality of System.Windows.Automation, and I have added assembly UIAutomationClient. When tried to run tests I got the folowing compiler error:

error CS0433: The type 'System.Windows.Automation.AutomationElement' exists in both 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\UIAComWrapper.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\UIAutomationClient.dll'

It was strange issue, because I didn't add UiaComWrapper assembly. Tried to remove the assembly, but as soon I run test the previous error appeared.

vsissue

 

Fixing the issue

To fix this issue we have to use "Reference Alias" which is specified here. So for our assembly UIAutomatisationClient change the Alias from "global" to  "UIAutomationClientAlias". See picture below.

vsissuesl2

Now that we defined new alias, in the following text it is shown how to use it in your cs file. Open the cs file we have error.

1. At the top opf the file put the folowing line:

extern alias UIAutomationClientAlias;

2. Define using namespace from the new alias:

using Autom = UIAutomationClientAlias::System.Windows.Automation;

3. Now we can use all members from Automation class safely, and the compiler error is despaired.

vsissuesl3

 


Posted Jun 16 2015, 05:41 PM by Bahrudin
developers.de is a .Net Community Blog powered by daenet GmbH.