how to fix the assembly problem when project A call project B as reference
2012-10-22 19:54
591 查看
1. Project B is coded with CodedUI Test
2. Project A is a Console Application, which has a reference from project B.
When run project A, there is a exception from project B on "playback.playbacksettings":
"
": Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Playback, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one
of its dependencies. The system cannot find the file specified.":"Microsoft.VisualStudio.TestTools.UITest.Playback, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Resolution:
1. Add reference to Microsoft.VisualStudio.TestTools.UITesting.dll, Microsoft.VisualStudio.TestTools.UITest.Extension.dll and Microsoft.VisualStudio.TestTools.UITest.Common.dll with CopyLocal as false.
2. Write an assembly resolver. Follow the code below
using System;
using System.Reflection;
using System.Globalization;
using System.IO;
using Microsoft.Win32;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
// Your code here.
}
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\10.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;
}
}
}
info from: http://blogs.kungfucoder.com/blog/post/2011/10/11/Coded-UI-Testing-Could-not-load-Visual-Studio-Test-Assembly.aspx
2. Project A is a Console Application, which has a reference from project B.
When run project A, there is a exception from project B on "playback.playbacksettings":
"
": Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Playback, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one
of its dependencies. The system cannot find the file specified.":"Microsoft.VisualStudio.TestTools.UITest.Playback, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Resolution:
1. Add reference to Microsoft.VisualStudio.TestTools.UITesting.dll, Microsoft.VisualStudio.TestTools.UITest.Extension.dll and Microsoft.VisualStudio.TestTools.UITest.Common.dll with CopyLocal as false.
2. Write an assembly resolver. Follow the code below
using System;
using System.Reflection;
using System.Globalization;
using System.IO;
using Microsoft.Win32;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
// Your code here.
}
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\10.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;
}
}
}
info from: http://blogs.kungfucoder.com/blog/post/2011/10/11/Coded-UI-Testing-Could-not-load-Visual-Studio-Test-Assembly.aspx
相关文章推荐
- how to fix the problem when you install matlab on *nix-- "libXp.so.6 : cannot open "
- how to fix the problem when you install matlab on *nix-- "libXp.so.6 : cannot open "
- How to fix the problem that the Download rate is too Slow when doing "apt-get install"
- How to fix the issue "A problem has been encountered while loading the setup components. Canceling setup"?
- How to solve the problem witch is the system send many emails when cron have something wrong
- How to solve the problem "A project with an Output Type of Class Library cannot be started directly "
- RunningMapReduceExampleTFIDF - hadoop-clusternet - This document describes how to run the TF-IDF MapReduce example against ascii books. - This project is for those who wants to experiment hadoop as a skunkworks in a small cluster (1-10 nodes) - Google Pro
- How to solve "one or more projects in the solution were not loaded correctly" problem?
- RunningMapReduceExampleTFIDF - hadoop-clusternet - This document describes how to run the TF-IDF MapReduce example against ascii books. - This project is for those who wants to experiment hadoop as a skunkworks in a small cluster (1-10 nodes) - Google Pro
- How to fix the problem of executing gitenv.csh file failed
- How to fix the python problem 'xxx() takes exactly one argument'
- How to fix the Android AVD no target problem
- How To Fix Xcode's "used as the name of&
- How to fix the problem 'Your CPU supports instructions that this TensorFlow binary was not compiled'
- How to fix OpenGL ES application crashes when moving to the background
- How to resolve the problem "Could not download sliverlight application" when doing deployment
- The project was not built due to "Could not delete ''.". Fix the problem, then try refreshing this p
- How do I fix the linker error in project upgraded from VS2010 to VS2013 where the linker is looking
- Q&A: HOW TO FIX XCODE’S "USED AS THE NAME OF THE PREVIOUS PARAMETER" WARNING
- 1.flex工程报错出现每次打开窗口的时候都会弹出一个窗口提示错误,提示“a problem has occurred when opening project "your project name",try to restart the applicat