i just added the refrence of Microsoft.VisualStudio.TestTools.UITesting
in my project and i try to use the ImageComparer` class but i get an error when running this
private void Form1_Load(object sender, EventArgs e)
{
Image a = Image.FromFile(@"C:\Users\itapi\Desktop\a.png");
Image b = Image.FromFile(@"C:\Users\itapi\Desktop\b.png");
ImageComparer.Compare(a,b);
}
the error is
An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.VisualStudio.TestTools.UITesting.dll
Additional information: The type initializer for 'Microsoft.VisualStudio.TestTools.UITest.Extension.UITestUtilities' threw an exception.
does anyone has any idea what's wrong here?
this is the innter excpetion
System.TypeInitializationException: The type initializer for 'Microsoft.VisualStudio.TestTools.UITest.Extension.UITestUtilities' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.WindowsStoreUtility, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at Microsoft.VisualStudio.TestTools.UITest.Extension.UITestUtilities..cctor() --- End of inner exception stack trace --- at Microsoft.VisualStudio.TestTools.UITest.Extension.UITestUtilities.CheckForNull(Object parameter, String parameterName) at Microsoft.VisualStudio.TestTools.UITesting.ImageComparer.CompareInternal(Image actualImage, Image expectedImage, ColorDifference argbTolerance, Image& diffImage, Boolean createOutImage) at Microsoft.VisualStudio.TestTools.UITesting.ImageComparer.Compare(Image actualImage, Image expectedImage, ColorDifference argbTolerance) at Microsoft.VisualStudio.TestTools.UITesting.ImageComparer.Compare(Image actualImage, Image expectedImage) at WindowsFormsApplication4.Form1.Form1_Load(Object sender, EventArgs e) in c:\Users\itapi\OneDrive\??????\Visual Studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Form1.cs:line 30
This question confuses me. Why focus on the exception instead of the problem? It appears you want to compare images. Why not ask how to compare images? A quick search will yield many results, like Fast Bitmap comparison - C#. I searched
c# compare images
and that was the 10th link. Others before that also have promise. What results do you want true/false, percentage match, image only and exif data mismatch ok, other?Also, when I look at the documentation for ImageComparer.Compare on MSDN, the signature differs from the sample code in this question. The documentation seems poor on this regarding usage, and if it should be used from within Visual Studio as others have discussed.
That's entirely expected. This assembly was meant to only be used from within Visual Studio. It is present in the C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies directory, quite out of reach from your Winforms app. The CLR will never find it.
Same is true for the Microsoft.VisualStudio.TestTools.UITesting.dll assembly but you got a copy in your bin\Debug directory because you referenced it.
These assemblies were only meant to be used to create unit tests, the kind that you run with the Test > Run menu item. The MSDN how-to article for creating coded UI tests is here.
You can copy the missing assembly with XCOPY in a post build event. But using the integrated unit test feature is certainly best and the only decent way to get a minimal guarantee that this still works when you update the VS version.