1
votes

I am trying to do UI automation using specflow/CodedUI/VSTS 2012.

When I try to run the scenario, I am getting the following error: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Playback, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Can anyone tell me how to resolve this error ?

1
Does this happen on your development machine, or only on a build server? - AlSki
It is happening on dev machine... - Sourabh

1 Answers

1
votes

Finally I found a way to resolve this problem. I do not know why but you have to write your own assembly resolver. I found the solution here:

http://blog.csdn.net/marryshi/article/details/8100194

However, I had to update the registry path for VS2012:

static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    AssemblyName assemblyName = new AssemblyName(args.Name);
    if (assemblyName.Name.StartsWith("Microsoft.VisualStudio.TestTools.UITest", StringComparison.Ordinal))
    {
        string path = string.Empty;
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\VisualStudio\11.0"))
        {
            if (key != null)
            {
                path = key.GetValue("InstallDir") as string;
            }
        }

        if (!string.IsNullOrWhiteSpace(path))
        {
            string assemblyPath = Path.Combine(path, "PublicAssemblies",
                string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name));

            if (!File.Exists(assemblyPath))
            {
                assemblyPath = Path.Combine(path, "PrivateAssemblies",
                   string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name));

                if (!File.Exists(assemblyPath))
                {
                   string commonFiles = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86);
                   if (string.IsNullOrWhiteSpace(commonFiles))
                   {
                       commonFiles = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles);
                   }

                   assemblyPath = Path.Combine(commonFiles, "Microsoft Shared", "VSTT", "10.0",
                       string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name));
                }
            }

            if (File.Exists(assemblyPath))
            {
                return Assembly.LoadFrom(assemblyPath);
            }
        }
    }

    return null;
}

And I registry resolver before running the feature:

[BeforeFeature]
public static void Initialize()
{
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}